Reset store not working on log out
victorkvarghese opened this issue · comments
Summary
I use zustand for all my projects. This library helps me a lot keeping things simple , powerful. Thanks a lot for maintaining #Zustand
App is not resetting the store after calling clearStorage. If i provide timeout , things are working. I need to know if this is the right way to clear storage and reset the store.
On log out i'm clearing the store and reloading the app. At first i thought store was not cleared because app didn't restart. So added RNRestart. but still things are not working. With timeout it works.
Do i need to manually reset each slice , even after clearing the storage?
Link to reproduction
const onLogOut = async () => {
RNQueryClient.clear();
RNQueryClient.invalidateQueries();
useCustomStore.persist.clearStorage();
useCustomStore.persist.rehydrate();
RNRestart.restart();
};
If i add timeout then it works,
const onLogOut = async () => {
RNQueryClient.clear();
RNQueryClient.invalidateQueries();
useCustomStore.persist.clearStorage();
setTimeout(() => {
useCustomStore.persist.rehydrate();
RNRestart.restart();
}, 400);
};
Version
React Native :
"zustand": "^4.4.4"
"react-native": "0.72.6",
@victorkvarghese How were you able to solve this issue? I am having the same problem of resetting the app every time for the storage to be cleared.