Git Product home page Git Product logo

Comments (3)

bobbyrenwick avatar bobbyrenwick commented on May 30, 2024 1

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 👍

from unstated-next.

mitramejia avatar mitramejia commented on May 30, 2024

great question i'm running into the same issue

from unstated-next.

crazy4groovy avatar crazy4groovy commented on May 30, 2024

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.)

from unstated-next.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.