You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, if I am understanding the conversation in #10743 correctly, useNavigate should be stable while navigating when using RouterProvider, but that's not the behavior I'm seeing.
You're confusing "stability" with "re-rendering". React always re-renders when state changes. The state changing is the global router state and it performs a top-down re-render. This is also what happens on your context access. This comment in the original issue speaks a bit to this: #7634 (comment).
The navigate function is stable when using RouterProvider which means that it's identity will not change across navigations and thus it will not trigger re-executions of effects on navigations when it's used as a dependency.
letnavigate=useNavigate();console.log("render");// This will log on location changesuseEffect(()=>{console.log("effect");// This will not log on location changes},[navigate]);
What version of React Router are you using?
6.14.2
Steps to Reproduce
Hi, if I am understanding the conversation in #10743 correctly,
useNavigate
should be stable while navigating when usingRouterProvider
, but that's not the behavior I'm seeing.Simple example: https://replit.com/@codebutler/React-Router-useNavigate-re-render-bug#src/App.tsx
Expected Behavior
Root component should not re-render when location changes.
Actual Behavior
Root component re-renders.
The text was updated successfully, but these errors were encountered: