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
When clicking the button in the Test component to switch routes, the Demo component will also be re rendered, and theoretically it should not be re rendered. If the demo does not use useNavigate(), everything will be normal
System Info
window
Used Package Manager
npm
Expected Behavior
v7: When switching routes, components using useNavigate() will be re rendered
Actual Behavior
v7: When switching routes, components using useNavigate() will be re rendered
The text was updated successfully, but these errors were encountered:
@yibird If you want to avoid this for now, you could wrap your useEffect or where you use it intouseRef to save a reference to the function. In that case your useEffect won't be affected by changing navigate
Or in your case, move the button which should trigger navigate() into separate function to re-render only this small component.
I don't know other options to avoid component re-rendering
I'm using React Router as a...
library
Reproduction
When clicking the button in the Test component to switch routes, the Demo component will also be re rendered, and theoretically it should not be re rendered. If the demo does not use useNavigate(), everything will be normal
System Info
Used Package Manager
npm
Expected Behavior
v7: When switching routes, components using useNavigate() will be re rendered
Actual Behavior
v7: When switching routes, components using useNavigate() will be re rendered
The text was updated successfully, but these errors were encountered: