reactjs – [RN] [Redux-Persist] AutoRehydrate不是一个函数
发布时间:2020-12-15 20:49:06 所属栏目:百科 来源:网络整理
导读:我正在使用redux-persist 5.5.0 当我调试我的本机应用程序时, 错误说“autoRehydrate不是函数” 我的源代码在这里,请给我帮助 "use strict";import thunk from "redux-thunk";import analytics from "./analytics";import array from "./array";import promi
我正在使用redux-persist 5.5.0
当我调试我的本机应用程序时, 错误说“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发生了变化,autoRehydrate不再使用了.以下是我现在使用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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容