Skip to content

[V4] <Match> / <Miss> children #4033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jampy opened this issue Oct 12, 2016 · 6 comments
Closed

[V4] <Match> / <Miss> children #4033

jampy opened this issue Oct 12, 2016 · 6 comments

Comments

@jampy
Copy link

jampy commented Oct 12, 2016

According to the docs, <Match> and <Miss> can only be configured using props and don't seem to expect any children.

Is there a good reason not to support (also) something like this?

<Match pattern="/foo">
  <SomeComponent>
    <div>
      Hello "foo"
    </div>
  </SomeComponent>
</Match>

<Match pattern="/bar">
  This is Bar!
</Match>

<Match pattern="/baz">
  <ComplexComponent
    what="ever"
    style={myStyle}
    coord={123}
    optimize={true}
    matrix={myMatrix}
  />
</Match>

I understand that this way the component does not receive props from Match/Miss, but for static routes (no :param) and for static content (for example, the This is Bar! text) this makes it much more readable, IMHO.

@jampy
Copy link
Author

jampy commented Oct 12, 2016

Additional use case:

<Match pattern="/config">
  <ConfigFrame>
    <Match pattern="/config/foo" component={FooConfig} />
    <Match pattern="/config/bar" component={BarConfig} />
    <Match pattern="/config/baz/:id" component={BazConfig} />
  </ConfigFrame>
</Match>

@timdorr
Copy link
Member

timdorr commented Oct 12, 2016

Match supports children. It's at the bottom of the page you linked. The reason we take a function is so the React Element doesn't have to be instantiated unless the Match matches. In your example, the child components are always instantiated, even if the pattern doesn't match.

@timdorr timdorr closed this as completed Oct 12, 2016
@ryanflorence
Copy link
Member

@jampy
Copy link
Author

jampy commented Oct 13, 2016

Thanks @timdorr and @ryanflorence for the hint. Makes a lot of sense performance-wise! :-)

Match supports children. It's at the bottom of the page you linked.

But children must be a function. Using simple React components like in my example above (accepting the performance risks you mentioned) leads to low level errors.

@ryanflorence
Copy link
Member

You should have gotten a propType warning: https://github.com/ReactTraining/react-router/blob/v4/modules/Match.js#L111

@jampy
Copy link
Author

jampy commented Oct 14, 2016

indeed

so, no components as childs

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants