我们正在使用react-persist,并且在初始化期间创建了一个持久性redux存储。
我们希望在初始化后(或在运行时)通过persistConfig
切换化简器的持久状态。
这可能吗?
这是我们在初始化期间创建商店的方式:
import { createStore } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web and AsyncStorage for react-native
import hardSet from 'redux-persist/lib/stateReconciler/hardSet'
import rootReducer from './reducers'
const persistConfig = {
key: 'root',
storage,
whitelist: ['visibilityFilter'] // navigation will not be persisted
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
export default () => {
let store = createStore(persistedReducer);
let persistor = persistStore(store);
return { store, persistor }
}