Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: useLocation causes rerenders, memoization impossible because of context. #10339

Open
DesertStrom16 opened this issue Apr 13, 2023 · 2 comments
Labels

Comments

@DesertStrom16
Copy link

What version of React Router are you using?

6.8.0

Steps to Reproduce

Add a useLocation hook to any component, then watch for re-renders with your tool of choice (Why-Did-You-Render in my case).

Expected Behavior

useLocation causes a re-render only when the location has changed.

Actual Behavior

Component re-renders (more than once, meaning not related to Strict Mode) even when location has not changed.

If this is unavoidable with Context, meaning we as developers cannot memoize, as well as the developers of this library cannot memoize, does that mean the only option left is to go old school with an event listener?

Thanks.

@timdorr
Copy link
Member

timdorr commented Apr 13, 2023

Can you give an example of this? Location has its own specific context, so it only updates when the location changes. Even if the pathname doesn't change, if you're triggering something that's causing another property of the location to change, that still will trigger a rerender (which is the correct behavior).

@process0
Copy link

This is a known bug with no official fix #7634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants