What is the use of autoRehydrate in redux-persist and why it was removed on v5?

Viewed 5397

I couldn't find anything on the GitHub page of ReduxPersist

I have a piece of code I'm trying to understand and as this autoRehydrate was removed, I would like to know how the code should be implemented with version 5 of redux-persist.

import { AsyncStorage } from 'react-native';
import { applyMiddleware, createStore } from 'redux';
import { autoRehydrate, persistStore } from 'redux-persist'
import thunk from 'redux-thunk';
import reducers from '../reducers';

const middleWare = [thunk];

const createStoreWithMiddleware = applyMiddleware(...middleWare)(createStore);

 export default configureStore = (onComplete) => {
  const store = autoRehydrate()(createStoreWithMiddleware)(reducers);
  persistStore(store, { storage: AsyncStorage }, onComplete);

  return store;
};

I've found some tutorials, but it just says this autoRehydrate must be there but doesn't explain what it actually does.

1 Answers

autoRehydrate means calling for the persist/REHYDRATE action to read the persisted state from the disk (which you have persisted before) which can be merged back to the original state.

In the migration guide from v4 to v5, they have introduced a PersistGate.

This delays the rendering of your app's UI until your persisted state has been retrieved and saved to redux.

Therefore all the rehydration actions will be handled by it under the hood.

Related