Feature request: usePathname #13553
philipburleigh
started this conversation in
Proposals
Replies: 2 comments
-
We need this badly! |
Beta Was this translation helpful? Give feedback.
0 replies
-
related discussion: #9851 |
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.
-
Hi DevTeam
As I understand, the best practice way of making a component reactive to the current pathname, is through useLocation():
const { pathname } = useLocation()
However, this approach comes with a downside. E.g. when query/search params are updated, the context for useLocation changes, which causes all component consuming useLocation() to rerender. In my case, this is quite annoying, since I only want my components to be reactive to the pathname.
It might be that I have missed a point in the documentation that addresses this issue. If so could you point me in the right direction? Otherwise I would suggest that you create a usePathname hook that is not affected by e.g. changes in query params.
Hope you can help👍
Beta Was this translation helpful? Give feedback.
All reactions