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

Store is not preserved through routes (react-router-dom) #115

Closed
ikanadev opened this issue Oct 15, 2020 · 2 comments
Closed

Store is not preserved through routes (react-router-dom) #115

ikanadev opened this issue Oct 15, 2020 · 2 comments

Comments

@ikanadev
Copy link

Hello, I'm really like kea, it's really powerful and simple to use. But seems like I found a bug?, here is the thing.

If a route (or any of its children components) are not using the store, this is reset to default values.
I mean:

<Switch>
          <Route path="/r1">
            <R1 />
          </Route>
          <Route path="/r2">
            <R2 />
          </Route>
          <Route path="/">
            <Home />
          </Route>
</Switch>

Here Home and R1 are using the store, this is preserved browsing between them. But if you go to R2 (which is not using the store) and come back to Home the store is reset to his default values. Here is a repo with the minimal files to demonstrate this: https://github.com/vmkevv/kea-with-react-router

I've already read all the documentation and didn't find a solution.

@mariusandra
Copy link
Member

Hey, logic is unmounted and its data cleared if it's not being used by any component.

The solution here would be to use

useMountedLogic(logic)

at the top of your <App />

@ikanadev
Copy link
Author

Thank you so much. It works perfectly.

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

2 participants