Skip to content

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

@kevin-from-atlassian

Description

@kevin-from-atlassian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions