Replies: 2 comments
-
Also useNavigate causes rerender. Are there any alternative to useNavigate? Nothing found in DOC. |
Beta Was this translation helpful? Give feedback.
-
React Router maintains a single state with the router state and pass it to a React context. Then every hook or component from the library depends on that context internally, and expose different parts of it. The useNavigation in particular changes the navigation.state from idle to loading and back to idle on any navigation. So this is what you see the rerenders, by calling useNavigation you're asking the router to let you know when navigation happens. But also because React context doesn't have selectors to only subscribe to parts of the context value then any change to the router state will trigger a rerender of your components using RE hooks So this is an expected behavior, and actually it's not bad, a rerender is how React works, if your app is slow because of this it's better to fix what's happening on each render that it's slow so you can let it keep rerendering as it needs. |
Beta Was this translation helpful? Give feedback.
-
React 19, RR 7.3
Is this actual behavior or am I doing something wrong?
Expected on page change no need rerender App, Layout but it rerender everything every route change.
Beta Was this translation helpful? Give feedback.
All reactions