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

Router state persists last value even when router is removed #177

Open
kevin-from-atlassian opened this issue Dec 8, 2022 · 0 comments
Open

Comments

@kevin-from-atlassian
Copy link

kevin-from-atlassian commented Dec 8, 2022

Codesandbox: https://codesandbox.io/s/react-resource-router-basic-routing-example-forked-x621v9

When the router is present, the query param updates as expected.
However, when the router is removed, the query param value persists the latest value (although it does not update when the query param is changed again). I would expect the value to be undefined (or perhaps an error to be thrown) since there is no router present, but it appears that the useQueryParam reads the value from a global state?

I encountered this with some jest tests, where a component utilizing query parameters had two tests. One wrapped, one not wrapped. Modifying the query param within the component from the wrapped test would affect the value of the query param in the test where the component was not wrapped, behavior that I would not have expected.

E.g.

test 1:
    <MemoryRouter><Component /></MemoryRouter>
    perform some action that changes the query parameter

test 2:
    <Component />
    the query parameter value from the useQueryParam hook is persisted from the previous test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant