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

[Question] What are some recommended patterns of clearing multiple containers at once? #50

Open
andrefox333 opened this issue Aug 16, 2019 · 3 comments

Comments

@andrefox333
Copy link

If I have multiple containers and I need to reset the state to initialState of each one upon let say when a user logs out. What is the best way of doing this? Not having each container's Provider on the App component makes this a bit challenging... Loving the library so far - just running into these little quirks. Open to suggestions and maybe other ways of tackling this problem. Thanks!

@mitramejia
Copy link

great question i'm running into the same issue

@crazy4groovy
Copy link

Great question. In my experience, this is where "events" come into play -- where one component can listen for dispatched events from another component. IMO this is where this library falls down -- it ties function execution to state manipulation too closely.

Redux-like solutions really shine here.

Event dispatching/listening is incredibly powerful. In your case, maybe and Auth component dispatches "auth/logout" event, and other components listen for "auth/logout" and do whatever they need to do, eg initialState. (This ability is why I use rematch on top of redux.)

@bobbyrenwick
Copy link

In the situation where you need to clear multiple containers when a user logs out you just need to make sure that all the <StateContainer.Provider>s you want to clear are unmounted when a user logs out.

See an example based off react router auth.

Click protected, log in, click buttons to update state, log out, then repeat to see the state being reset to the initial state. Hope that helps 👍

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

4 participants