You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This problem has come up in a number of different forums. The work-around is awkward enough, and an elegant solution is simple enough, that I'm not sure why this hasn't already been implemented.
Currently, in order to pass props to a component associated with a route, you have to use the following idiom:
This gets the job done, but it's not very elegant, and certainly not easy to read. This is attested to by the fact that a FAQ entry had to be created to address it. Why not just have the Route component include any extraneous props in the standard props that it passes to the component?
Yes, I'm aware that this has been the subject of much discussion. But the fact that this is the subject of an entire FAQ entry suggests that the current solution isn't very intuitive.
If we're trying to do it the "react way," then wouldn't it make more sense to take advantage of the built-in children collection? Using props to pass render functions around feels like a hack when you could do this instead:
This problem has come up in a number of different forums. The work-around is awkward enough, and an elegant solution is simple enough, that I'm not sure why this hasn't already been implemented.
Currently, in order to pass props to a component associated with a route, you have to use the following idiom:
<Route path="/myComponent" render={(props) => <MyComponent {...props} myProp="myValue" />} />
This gets the job done, but it's not very elegant, and certainly not easy to read. This is attested to by the fact that a FAQ entry had to be created to address it. Why not just have the Route component include any extraneous props in the standard props that it passes to the component?
<Route path="/myComponent" component={MyComponent} myProp="myValue" />
I'm relatively new to react, so maybe this isn't as trivial as I imagine.
The text was updated successfully, but these errors were encountered: