question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redux Persist not working on IOS... works well on android

See original GitHub issue

Redux persist works on android but is not working on IOS 11.0 my code is as below

// store.js
export const configureStore(intialState){
const rootPersistConfig = {
  key: "root",
  storage: storage,
  debug: true
};

const persistedReducer = persistReducer(rootPersistConfig, rootReducer);

middlewares = [...];

let store = createStore(
    persistedReducer,
    initialState,
    composeEnhancers(applyMiddleware(...middlewares))
  );
let persistor = persistStore(store);
return { persistor, store };
}

and my app.js is as follows

// app.js
// other imports
const { persistor, store } = configureStore({});

export default App extends Component {
// all other things

render() {
    return (
      <Provider store={store}>
        <AlertProvider>
          <Root>
            <PersistGate persistor={persistor} loading={null}>
              <RootNav />
            </PersistGate>
          </Root>
        </AlertProvider>
      </Provider>
    );
  }
}

I also had redux-logger which I checked in the console neither the PERSIST event nor REHYDRATE occurs. The persistGate never gets lifted. Please help stuck from past 4 days. 😦 thanks in advance

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

9reactions
ltankeycommented, Mar 16, 2018

Argh I’m having the opposite - works fine on iOS simulator but not on a connected Android device! Hopefully it’s a related issue and someone can respond…

3reactions
evertoncocommented, Oct 4, 2018

App.js

export default class App extends React.Component {
  render() {
    return (
      <ApolloProvider client={client} store={store}>
        <AppNavigator {...this.props} />
      </ApolloProvider>
    );
  }
}

navigator.js

export const AppNavigator = createSwitchNavigator(
  {
    AppLoading,
    App,
    Auth,
  },
);

app-loading.js

class AppLoading extends Component {

  storeReady = false;
  // other variable definitions

  state = {};

  componentWillMount() {
    
    const { _persist } = this.props;
    
    // set flag (expected be true)
    this.storeReady = _persist.rehydrated;
    ...
  }

  componentWillReceiveProps({ _persist }) {

    // check for REHYDRATE event (On IOS, this event is not fired. On android, works correctly)
    if (!this.props._persist.rehydrated && _persist.rehydrated) {

      this.storeReady = true;
      ...
    }
  }

  // I'm using Expo. So, I check if this.storeReady flag is true to allow app to go to next screen:
  handleFinishLoading = () => {
    if(this.storeReady) {
      // logic to check if user is authenticated or other stuff and redirect to correct screen
      this.props.navigation.navigate('NextScreen');
    } else {
       // redirect to error screen?!
    }
  }

  render() {
    return (
      <Expo.AppLoading
        startAsync={this.handleLoadResources}
        onError={this.handleLoadingError}
        onFinish={this.handleFinishLoading}
      />
    );
  }
}

// redux mapping to get access to _persist prop
const mapStateToProps = ({ _persist }) => ({ _persist });

export default connect(mapStateToProps)(AppLoading);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why redux-persist doesn't persist my data? - Stack Overflow
I made a reducer called handleUser that allows users to sign in. It works perfectly without redux-persist, but when I use it, the...
Read more >
How To Use Redux Persist in React Native with Asyncstorage
The Redux Persist library provides an easy way to save a Redux store in the local storage of React Native apps. In this...
Read more >
React native redux: how to use it? - Imaginary Cloud
Wondering how you can use redux and redux toolkit when ... We are using an Android emulator, but redux-persist also works with IOS....
Read more >
Redux-persist: The Good parts - codeburst
If you are trying to migrate from redux-persist V5 to Filesystem storage on Android you may run into issues with holding onto your...
Read more >
How to Persist Your Redux Store - How-To Geek
You now need to connect the library to your store. Wrap your root reducer using Redux Persist's persistReducer function. This lets Redux Persist ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found