rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.97k stars 867 forks source link

Question: Synchronously notified when persist completes #1000

Open yarrichar opened 5 years ago

yarrichar commented 5 years ago

I've been trying to work out if it is possible to have some code that dispatches an action, and then waits for it to be fully persisted to disk (by redux-persist) before continuing on.

Is something along the lines of the following guaranteed to do what I want? I guess my main thing that isn't clear to me is what state the store is in after the call to dispatch - i.e. whether the persistor will have run by this time.

try {
    await store.dispatch(someAction());
    await persistor.flush();
} catch (e) {
    // handle the error
}
AlexisGado commented 3 years ago

Did you find a solution ? I'm struggling with the same kind of questions !