rt2zz / redux-persist

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

Cannot read property 'subscribe' of undefined #979

Closed isaaclem closed 5 years ago

isaaclem commented 5 years ago

App.js

import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';

import { store, persistor } from './configureStore';
import Router from './Router';

class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
          <Router />
        </PersistGate>
      </Provider>
    );
  }
}

export default App;

configureStore.js

import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web and AsyncStorage for react-native
import { applyMiddleware, compose } from 'redux';
import ReduxThunk from 'redux-thunk';

import Reactotron from '../ReactotronConfig';
import rootReducer from './reducers';

const persistConfig = {
  key: 'root',
  storage
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

export default () => {
  const store = Reactotron.createStore(
    persistedReducer,
    undefined,
    compose(applyMiddleware(ReduxThunk))
  );
  const persistor = persistStore(store);
  return { store, persistor };
};

Nearly didn't change anything from documentation but when I reload the app, I'm hitting

TypeError: Cannot read property 'subscribe' of undefined.

This error is located at: in PersistGate (at App.js:14)

isaaclem commented 5 years ago

My bad, the problem is with the import statement at App.js

Wrong

import { store, persistor } from './configureStore'

Correct

import Store from './configureStore';

<Provider store={Store().store}>
...
SinaKarimi7 commented 5 years ago

same but not solved yet

pisacode commented 5 years ago

https://stackoverflow.com/a/51519967/5069866 this is how to solve it