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

时间:2018-09-18 20:35:20

标签: javascript reactjs react-native redux redux-persist

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 个答案:

答案 0 :(得分:3)

autoRehydrate意味着要求执行persist/REHYDRATE操作以从磁盘读取持久状态(您之前已保留),该状态可以合并回到原始状态。

在从v4到v5的迁移指南中,他们引入了PersistGate

这将延迟应用程序UI的呈现,直到检索到您的持久状态并将其保存到redux。

因此,所有的补液动作都将在引擎盖下进行。

相关问题