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

No way to reset the store. #146

Closed
Windynik opened this issue Apr 5, 2019 · 5 comments
Closed

No way to reset the store. #146

Windynik opened this issue Apr 5, 2019 · 5 comments

Comments

@Windynik
Copy link

Windynik commented Apr 5, 2019

In the application that we're building, after the user logs out, there's no way to reset the store.

We have tried setting it to undefined,null or an empty object(it crashes the app), but that doesn't help.

@Windynik
Copy link
Author

Any update?

@revskill10
Copy link
Contributor

You can add a resetStore action ?

@Windynik
Copy link
Author

@revskill10 We tried that, but it didn't make any change.

@ctrlplusb
Copy link
Owner

As a temporary solution you could do something similar to:

const store = createStore({
  ...,
  setState: action((state, payload) => payload),
});

const initialState = store.getState();

// Later... reset store
store.dispatch.setState(initialState);

@ctrlplusb
Copy link
Owner

And if you would like it wrapped in an action...

let initialState = {}

const store = createStore({
  ...,
  reset: action((state, payload) => ({
   ...initialState,
  }),
});

initialState = store.getState();

// Later... reset store
store.dispatch.reset();

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

3 participants