wwayne / redux-reset

Give redux the ability to reset the state
MIT License
96 stars 7 forks source link

Problems with redux-persist v5 #7

Open giacomocerquone opened 6 years ago

giacomocerquone commented 6 years ago

Hi, I believe this package has some issues with redux-persist v5. Basically it's like it resets the state but the redux-persist package for some reason doesn't write the updated state to the storage system (asyncstorage in my situation).

But if I create a reset action by hand (that brings the state to its initial state), it works correctly. I'm integrating your package like this:

createStore(
  rootReducer,
  undefined,
  compose(
    applyMiddleware(
      thunkMiddleware,
      loggerMiddleware,
    ),
    reduxReset('RESET_APP')
  )
)

What may be causing this issue?

ritz078 commented 6 years ago

@giacomocerquone did you find a solution to this ?

DavitVosk commented 6 years ago

I have the same problem here for "redux-persist": "5.4.0". Can you please help to find a solution

giacomocerquone commented 6 years ago

@ritz078 no, for now I made myself happy using handmade RESET actions

DavitVosk commented 6 years ago

Yes @giacomocerquone, I make it by hand as well and it works. But it would be better if this package could handle it itself as it has to do

GlisboaDev commented 5 years ago

I'm not using redux-reset (implemented a solution myself), but came across the same issue. It seems redux-persist doesn't like 'reseting' the state. We resolved the situation by pausing the persistor ((persistor.pause()) before setting the store state, then resuming (persistor.persist()) it right after reseting, and everything works fine. So we get a flow like: pause persistence -> reset store state -> resume persistence.

Hope it helps!

milasevicius commented 5 years ago

When we reset our state and purge storage, state is not persisted anymore - running persistor.persist() solves this issue.

Example code:

export function logout() {
  return async dispatch => {
    dispatch({ type: 'RESET' })
    await persistor.purge()
    await persistor.persist()
  }
}
foloinfo commented 3 years ago

I had the same issue. It seems like { type: 'RESET' } will remove the _persistor state and it causes redux-persist not to persist anymore. I found it will be persisted if you pass an initial state.

dispatch({
  type: 'RESET',
  state: {
    _persist: { version: 1, rehydrated: true }
  }
})

I hope this helps.