0

I have the following Route which renders when the path is matched:

<Route exact path="/create-team" render={() => <TeamNameCard/>}/>

This properly renders the <TeamNameCard/> component, however the match, location, and history props are not available in this.props.

However, when rendering the component using the following, those props are available:

<Route exact path="/create-team" component={TeamNameCard}/>

According to the documentation, all render methods should receive these same props. Why is this not working as expected?

EDIT: I've noticed that the following syntax seems to give me access to the needed route props:

render={(props) => <TeamNameCard {...props} />

I've yet to see this before. Is this correct, or is there a better way?

Orbit
  • 2,985
  • 9
  • 49
  • 106
  • 1
    It's correct. The link you posted has an example that passes props the same way – FuzzyTree Sep 25 '17 at 01:23
  • 1
    A better way is to use `component={TeamNameCard}` is you don't explicitly need to pass some custom pros to the component, otherwise pass the default props with the `render` as mentioned in the answer to the duplicate question – Shubham Khatri Sep 25 '17 at 10:00
  • @ShubhamKhatri Thank you for noting the duplicate, it explained the answer well. – Orbit Sep 25 '17 at 13:13

0 Answers0