现在,我正在尝试将 redux persist 集成到我的 redux-saga 中以做出本机反应。我已经在 CreateStore 中尝试了一些代码。我的应用程序可以运行,但减速器总是在重新加载应用程序后重置。
这是我的代码
// CreateStore.js
import { applyMiddleware, compose } from 'redux'
import createSagaMiddleware from 'redux-saga'
import { persistStore, persistCombineReducers } from 'redux-persist';
import { AsyncStorage } from 'react-native';
import Reactotron from "reactotron-react-native";
const config = {
key: 'root',
storage: AsyncStorage,
};
// creates the store
export default (rootReducer, rootSaga) => {
/* ------------- Redux Configuration ------------- */
const middleware = []
const enhancers = []
/* ------------- Saga Middleware ------------- */
const sagaMiddleware = createSagaMiddleware()
middleware.push(sagaMiddleware)
/* ------------- Assemble Middleware ------------- */
enhancers.push(applyMiddleware(...middleware))
const reducers = persistCombineReducers(config, rootReducer);
const persistConfig = { enhancers };
const store = Reactotron.createStore(rootReducer, compose(...enhancers));
persistStore(store);
// kick off root saga
sagaMiddleware.run(rootSaga)
return { store };
}
// app.js
import React, { Component } from "react";
import { Provider } from "react-redux";
import Reactotron from "reactotron-react-native";
import createStore from '../src/Redux'
import PrimaryNav from "../src/navigations/AppNavigations";
export default class App extends Component {
render() {
const { store } = createStore()
console.log = Reactotron.log
console.disableYellowBox = true;
return (
<Provider store={store}>
<PrimaryNav />
</Provider>
);
}
}
有没有人有解决这个问题的线索?我希望减速器在重新加载应用程序之前保留以前的数据。
感谢大家