Redux-persist中的autoRehydrate有什么用处?为什么它在v5中被移除了?

3

我在ReduxPersist的GitHub页面上找不到任何信息。

我有一段代码想要理解,由于autoRehydrate已被移除,我想知道如何使用redux-persist版本5来实现该代码。

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;
};

我找到了一些教程,但它只是说必须有 autoRehydrate,但并没有解释它实际上是做什么的。

1个回答

5
autoRehydrate是指调用persist/REHYDRATE操作从磁盘中读取已经存储的状态(在之前您已经持久化了),该状态可以与原始状态合并。

在从v4迁移到v5的迁移指南中,他们介绍了一个PersistGate

这会延迟渲染应用程序的UI,直到您的持久化状态已经被检索并保存到redux中。

因此,所有的rehydration操作都将在其内部处理。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接