javascript - 在 redux-persist 中 autoRehydrate 有什么用,为什么它在 v5 中被删除?
问题描述
我在ReduxPersist的 GitHub 页面上找不到任何东西
我有一段我试图理解的代码,因为它被删除了,autoRehydrate
我想知道应该如何使用.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;
};
我找到了一些教程,但它只是说这autoRehydrate
必须存在,但没有解释它的实际作用。
解决方案
autoRehydrate
意味着调用操作从磁盘persist/REHYDRATE
(您之前已持久化)读取持久化状态,可以将其合并回原始状态。
在从 v4 到 v5 的迁移指南中,他们引入了PersistGate。
这会延迟应用 UI 的呈现,直到您的持久状态被检索并保存到 redux。
因此,所有的补液动作都将由它在引擎盖下处理。
推荐阅读
- javascript - Array.reduce - 对象的奇怪行为
- c++ - MsWord API - 如何将表格单元格的内容从一个转移到另一个
- mysql - mysql查询语法错误,在mysql8.0之后不能在UNION之前使用LIMIT?
- python - 带有默认字段的Django模型序列化问题
- ruby-on-rails - 在任何带有Passenger的来源(Bundler::GemNotFound)中都找不到i18n-1.1.1
- ios - 如何分配“UIImage”类型的值?输入“UIView?”
- angular - 使用 Angular 原理图创建新模块
- java - org.springframework.dao.DataIntegrityViolationException on API 调用
- java - 改造抛出错误预期 BEGIN_OBJECT 但 BEGIN_ARRAY 从数组列表到列表?
- android - 如何解决 java.lang.StringIndexOutOfBoundsException?