问题
I am using Redux persist to persist my store for reducers. My application has two reducers Navigation and User Reducer.I want to persist only user state but I have to persist both states according to this syntax of redux persist.
import {persistStore, autoRehydrate} from 'redux-persist'
const store = createStore(reducer, undefined, autoRehydrate())
persistStore(store)
the reducer that I have passed in the create store is the object of combine reducers.
Problem: The problem I am getting through this is when I exit my app, as the navigation state is also persist now, my app opens the same page from which I exited my app.
I am using navigation experimental with redux in my app and want to persist only user state.
回答1:
redux-persist v5
Set the blacklist/whitelist in the PersistConfig, and use it in persistCombineReducers (the 1st param):
const persistConfig = {
key: 'root',
blacklist: ['navigation'],
storage,
}
const reducer = persistCombineReducers(persistConfig , reducers)
redux-persist v4
persistStore can have an optional config object as the 2nd parameter. In the config object, you can define a black list of reducers to ignore, or a white list of reducers to include (and ignore the rest). Both accept an array of reducers' key names.
You can blacklist the navigation (or whatever yours is called) reducer:
persistStore(store, { blacklist: ['navigation'] })
来源:https://stackoverflow.com/questions/42018091/how-can-i-use-redux-persist-for-only-one-reducer-not-for-navigation-reducer-in-m