react-nativereact-reduxredux-toolkitredux-persist

React-Native Redux-Toolkit Redux-Persist: Cannot read property 'dispatch' of undefined


Here's the error that is shown in Emulatorenter image description here

This error has appeared while I was integrating redux-persist with Redux Toolkit in the React-native application. I have tried to find various solutions but failed to do so. Any help is appreciated.


Solution

  • This issue has occurred due to the misplacement of the persistStore() code which needed store as a parameter. Its working fine when placed after the store creation code snippet.

    Before (Not Working):

    export const persistor = persistStore(store); // this line should be after creating the store.
    
    export const store = configureStore({...}); // store creation.
    

    After (Working):

    export const store = configureStore({...}); // store creation.
    export const persistor = persistStore(store); // Here it is working fine.