Easy-peasy: No way to reset the store.

Created on 5 Apr 2019  路  5Comments  路  Source: ctrlplusb/easy-peasy

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.

Most helpful comment

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();

All 5 comments

Any update?

You can add a resetStore action ?

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

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

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();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

djgrant picture djgrant  路  6Comments

lishine picture lishine  路  6Comments

vincentjames501 picture vincentjames501  路  6Comments

raul-madrigal picture raul-madrigal  路  3Comments

positimo picture positimo  路  3Comments