Replies: 1 comment 4 replies
-
|
We like this, we're thinking we can overload |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I had created an issue here but have just seen this new place where proposals apparently live now so I'm transfering it here:
What is the new or updated feature that you are suggesting?
Allowing the
childrenof theRoutecomponent to be a function/render prop and pass in thematchobjectWhy should this feature be included?
In previous versions of
react-routerwe were able to use arenderprop on theRoutecomponent to render our pages/components when matching the given path and this render prop was given aroutePropsargument. I agree that most of the props in thisroutePropswere not very useful as we could just use the hooks/HOC to get them, but thematchobject was very useful and informative as it allowed us to keep the path/params logic in the routes. The TypeScript inferance that we had on top of that was amazing, it allowed us to have strongly typed params in the path and pass them down as props to the rendered components rather than rely on the "unreliable"useParams.This implementation here uses react-router@5. Passing the
pathprop as aconstallowed us to be 100% sure we had theblogPostIdparam and that we were passing this down declaratively to ourBlogPost:With the react-router@6 way we have to trust that the
BlogPostcomponent is actually rendered under aRoutethat has theblogPostIdparam in its path. We are passing a generic to theuseParamhook and essentially saying: give me whatever param you have from the URL but just cast it to what I think is there, might not be though.Funny enough I had made mistake in the react-router@6 example at the start as I had written it like this, which TypeScript is fine with but
iddoes not actually exist in the params, it should beblogPostId:Thank you for considering this!
Beta Was this translation helpful? Give feedback.
All reactions