Replies: 2 comments
-
The same as #7875 |
Beta Was this translation helpful? Give feedback.
-
What would you propose this looks like? A If you want the pathname in a component without worrying about the rest of the location, I imagine you'd need to do that with function Parent() {
let navigate = useNavigate()
let { pathname } = useLocation();
return <Child pathname={pathname} navigate={navigate} />
}
function Child_({ pathname, navigate }) {
return null; // return whatever
}
// Child will not re-render if `location` changes
// (basename or pathname updating will still update navigate here)
// Move any perf bottlenecks into the child
const Child(Child_); |
Beta Was this translation helpful? Give feedback.
-
What is the new or updated feature that you are suggesting?
A hook usePathname should be created.
Why should this feature be included?
Currently, the useNavigate hook triggers a rerender on any change to the state or SearchParams. useNavigate, however, only needs the path, but uses useLocation for it. It would therefore save performance if useNavigate did not render on every change. In general, usePathname would also be handy for various other use cases.
Beta Was this translation helpful? Give feedback.
All reactions