作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 redux-persist 5.5.0当我调试我的 react native 应用程序时,错误提示“autoReHydrate 不是一个函数”我的源代码在这里,请给我帮助
"use strict";
import thunk from "redux-thunk";
import analytics from "./analytics";
import array from "./array";
import promise from "./promise";
import reducers from "../reducers";
import { createLogger } from "redux-logger";
import { applyMiddleware, createStore, compose } from "redux";
import { persistStore, autoRehydrate } from "redux-persist";
import { ensureCompatibility } from "./compatibility";
import { AsyncStorage } from "react-native";
const isDebuggingInChrome = false;
const logger = createLogger({
predicate: (getState, action) => isDebuggingInChrome,
collapsed: true,
duration: true
});
const middleware = applyMiddleware(thunk, promise, array, analytics, logger);
async function configureStore(onComplete: ?() => void) {
const didReset = await ensureCompatibility();
const store = createStore(reducers, { /* TODO: Initial state */ }, compose(middleware, autoRehydrate()));
persistStore(store, { storage: AsyncStorage }, _ => onComplete(didReset));
if (isDebuggingInChrome) {
window.store = store;
}
return store;
}
最佳答案
redux-persist 5.x 对 API 进行了更改,并且不再使用 autoRe一线。下面是我现在使用 redux-persist 的方式。
import React, {Component} from 'react';
import {Provider} from 'react-redux';
import {createStore, applyMiddleware, compose} from 'redux';
import {PersistGate} from 'redux-persist/lib/integration/react';
import {persistStore, persistReducer} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import Thunk from 'redux-thunk';
import Router from './Router';
import reducers from './reducers';
const persistConfig = {
key: 'root',
storage: storage,
};
const persistedReducer = persistReducer(persistConfig, reducers);
const store = compose(persistedReducer, {}, composeEnhancers(applyMiddleware(Thunk)));
class App extends Component {
render() {
const persistor = persistStore(store);
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
<Router />
</PersistGate>
</Provider>
);
}
}
export default App;
关于reactjs - [RN][Redux-Persist] AutoReHydrate 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48514147/
我正在使用 redux-persist 5.5.0当我调试我的 react native 应用程序时,错误提示“autoReHydrate 不是一个函数”我的源代码在这里,请给我帮助 "use str
我在 ReduxPersist 的 GitHub 页面上找不到任何内容。 我有一段代码试图理解,由于此 autoRehydrate 已被删除,我想知道应该如何使用 version 5 实现代码redu
我是一名优秀的程序员,十分优秀!