feat(react): Support useRoutes hook of React Router 6.#5624
feat(react): Support useRoutes hook of React Router 6.#5624AbhiPrasad merged 4 commits intomasterfrom
useRoutes hook of React Router 6.#5624Conversation
AbhiPrasad
left a comment
There was a problem hiding this comment.
Will this cause any issues with https://reactjs.org/docs/hooks-rules.html?
It seems meeting the requirements:
1 - We're calling all hooks from the top level of a functional React component that we return, including the original 2 - There are no early returns inside the hook. The one early return happens outside of React component context, and returns the original
This also passes Would be better if I renamed the wrapped hook as The open issue (#5309) probably will apply to this as well, though. Maybe I should focus on that next. WDYT? |
We should name it I think it's reasonable to look at #5309 after this as well! |
Resolves: #5338
This PR introduces
wrapUseRoutesfunction, which can be used to patchuseRouteshook of React Router 6.Example usage:
Note:
createRoutesFromChildrenis not used bywrapUseRoutes. But, not to break the API (parameter order) ofreactRouterV6Instrumentation, I had to keep it as the 4th argument.wrapUseRoutesdoesn't do a null check for it though, so it's safe to pass anything with the current implementation. Any suggestions?