在 redux-persist 中自动解除冻结有什么用,为什么在 v5 上将其删除?



我在 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必须在那里,但没有解释它的实际作用。

autoRehydrate表示调用persist/REHYDRATE操作以从磁盘(您之前已持久化(读取持久状态,该状态可以合并回原始状态。

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

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

因此,所有解除冻结操作都将由它在后台处理。

最新更新