如何在运行时从react-persist编辑持久性存储

时间:2019-03-20 08:08:46

标签: reactjs redux react-redux redux-persist

我们正在使用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 }
}

0 个答案:

没有答案