rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.91k stars 863 forks source link

TypeError: this.props.persistor.subscribe #896

Open mohammad1990 opened 5 years ago

mohammad1990 commented 5 years ago

Hi,

I'm using redux-persist ^5.10.0", but I get always this error :

TypeError: this.props.persistor.subscribe is not a function
PersistGate.componentDidMount
client/node_modules/redux-persist/es/integration/react.js:53
  50 | _createClass(PersistGate, [{
  51 |   key: 'componentDidMount',
  52 |   value: function componentDidMount() {
> 53 |     this._unsubscribe = this.props.persistor.subscribe(this.handlePersistorState);
  54 |     this.handlePersistorState();
  55 |   }
  56 | }, {
View compiled
commitLifeCycles
client/node_modules/react-dom/cjs/react-dom.development.js:14361
  14358 |   startPhaseTimer(finishedWork, 'componentDidMount');
  14359 |   instance.props = finishedWork.memoizedProps;
  14360 |   instance.state = finishedWork.memoizedState;
> 14361 |   instance.componentDidMount();
  14362 |   stopPhaseTimer();
  14363 | } else {
  14364 |   var prevProps = current.memoizedProps;

Store code:

const initialState = {};
const middleware = [reduxThunk];
const persistConfig = {
  key: 'root',
  storage,
  whitelist: ['auth'],
};
const persistedReducer = persistReducer(persistConfig, rootReducer)
const store = createStore(
  persistedReducer,
  initialState,
  composeWithDevTools(
    applyMiddleware(...middleware),

  )
);
const persistor = persistStore(store);
export default { store, persistor };

Index.js

import store from './store';
import persistor from './store';
ReactDom.render(
  <Provider store={store}>
    <PersistGate loading={null} persistor={persistor}>
      <App />
    </PersistGate>
  </Provider>
  , document.querySelector('#root')
);

Any Help Please :)

Johncy1997 commented 5 years ago

I am facing the same issue for 2days..Please tell me what is solution for this

Frikster commented 5 years ago

@Johncy1997 is your webpack server running? I had the same issue and noticed I forgot to start it up again.

SinaKarimi7 commented 5 years ago

Same, I'm facing too!

My app contains of redux-saga, immutablejs and redux-persist.

this.props.persistor.subscribe is not a function

Johncy1997 commented 5 years ago

@Johncy1997 is your webpack server running? I had the same issue and noticed I forgot to start it up again.

I removed the PersistGate component and manually rehydrated my whitelist reducers.:( still i dont know the exact problems.

MaxiSantos commented 5 years ago

@mohammad1990 where does the createpersistor comes from? I've found that depending on the library it may return different persistor without the subscribe method