Replies: 1 comment 3 replies
-
We like this, we're thinking we can overload |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
children
of theRoute
component to be a function/render prop and pass in thematch
objectWhy should this feature be included?
In previous versions of
react-router
we were able to use arender
prop on theRoute
component to render our pages/components when matching the given path and this render prop was given arouteProps
argument. I agree that most of the props in thisrouteProps
were not very useful as we could just use the hooks/HOC to get them, but thematch
object 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
path
prop as aconst
allowed us to be 100% sure we had theblogPostId
param and that we were passing this down declaratively to ourBlogPost
:With the react-router@6 way we have to trust that the
BlogPost
component is actually rendered under aRoute
that has theblogPostId
param in its path. We are passing a generic to theuseParam
hook 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
id
does not actually exist in the params, it should beblogPostId
:Thank you for considering this!
Beta Was this translation helpful? Give feedback.
All reactions