A hook for returning the currently rendering match. #6237
rossipedia
started this conversation in
Proposals
Replies: 1 comment
-
Related - we have Related Issue asking for a similar concept: remix-run/react-router#9543 |
Beta Was this translation helpful? Give feedback.
0 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.
-
A useful thing to know is "what part of my route structure is currently rendering?"
This can help in scenarios where you don't care about the URL or the route structure above you, but you care about something below you, and want to handle them in a generic fashion.
An example would be something like MUI's Tabs and Tab component in a component used in a layout route:
Currently, in order for this to work you have to hard-code the path prefix in the
useMatch()
call:While this can be abstracted out to a prop passed in, it still makes things a bit tedious if you need to shuffle around your route files/url structure.
Knowing which entry in
useMatches()
is currently being rendered can open the door for some really cool generic solutions, I think.Another viable solution would be to have a hook that returns the route id for the currently rendering route, something like
useCurrentRouteId()
. This would allow you to look up the match directly by usinguseMatches()
. Either approach would solve the problem.Beta Was this translation helpful? Give feedback.
All reactions