Search code examples
react-nativereduxreact-reduxredux-persistredux-offline

Purge or call action to reset states?


My application is using the redux-offline package which has the ability to persist store. I came across this concept purge which seems to reset states upon loading app.

My apps have a sign out function in which it makes sense to clean the localStorage/cache. I'm wondering if in this case I should use the purge concept or create an action that resets all reducers instead?


Solution

  • The redux-offline uses redux-persist under the hood to retain the redux state into the storage.

    But there may be a case where you are blacklisting some reducers.

    const persistConfig = {
      key: 'root',
      storage: storage,
      blacklist: ['// Any such blacklisted reducer']
    };
    

    Therefore .purge method would be useful in such a case where you just want to reset state stored in the disk but not completely reset the reducer state.