rt2zz / redux-persist

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

redux persist does not work on android #906

Open damathryx opened 6 years ago

damathryx commented 6 years ago

I've been stuck on this for some time, it works perfectly in iOS but doesn't work in Android. redux-persist 5.10.0 react-native 0.56.0

screen shot 2018-09-12 at 10 44 40 pm
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { persistCombineReducers } from 'redux-persist';
import storage from 'redux-persist/es/storage';
import stateReconciler from 'redux-persist/lib/stateReconciler/hardSet'
import logger from 'redux-logger';

import reducer from './reducers';

const createStoreWithMiddleware = applyMiddleware(thunk, logger)(createStore);

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

const combinedReducer = persistCombineReducers(persistConfig, reducer)

export default createStoreWithMiddleware(combinedReducer);
import { Provider } from 'react-redux'
import { persistStore as persistStoreRaw } from 'redux-persist';
import { Navigation } from "react-native-navigation";

import { registerScreens } from './screens'
import { registerComponents } from './components'
import { launchApp, trackScreen } from './navigation'

import store from './store'

const initialize = () => {
  return persistStoreRaw(store, null, () => {
      registerScreens({ Provider, store })
      registerComponents()
      trackScreen(store)
      const { user } = store.getState()
      launchApp(user.loggedIn)
  })
}

export default initialize()
bluenex commented 6 years ago

I've also faced this. There is a closed issue pointing that it was npm bug. But that doesn't seem to be my case.

How do I log just like your?

damathryx commented 6 years ago

@bluenex i'm using redux-logger

Blackfaded commented 6 years ago

I am facing the same issue. App is starting, but state is not persisted.

"react-native": "~0.55.2",
"react-native-navigation": "^1.1.471",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-persist": "^5.10.0"
nighttiger1990 commented 6 years ago

Same issue. When i'm in debug mode, it show console.error: "redux-persist: rehydrate for "root" called after timeout.", {....}, undefined

andrewmarmion commented 6 years ago

I was having a similar problem with my set up. iOS was working but Android was not. I resolved it by adding keyPrefix: '' to the persist config.

https://github.com/leethree/redux-persist-fs-storage/issues/5#issuecomment-409962329

SamiChab commented 5 years ago

I had the problem because I was calling persistStore( ... ) two times in my code (in two different files)

nirajniroula commented 4 years ago

Had same issue. Fixed using timeout: null in persist config.

const persistConfig = {
  key: 'root',
  storage,
  timeout: null,
}