
How can I use redux persist for only one reducer not for navigation reducer in my react native appli
Question:
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.
<strong>Problem:</strong> 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.
Answer1:<a href="https://github.com/rt2zz/redux-persist" rel="nofollow">redux-persist v5</a>
Set the blacklist/whitelist in the <a href="https://github.com/rt2zz/redux-persist/blob/master/docs/api.md#type-persistconfig" rel="nofollow">PersistConfig</a>, and use it in <a href="https://github.com/rt2zz/redux-persist#usage" rel="nofollow">persistCombineReducers</a> (the 1st param):
const persistConfig = {
key: 'root',
blacklist: ['navigation'],
storage,
}
const reducer = persistCombineReducers(persistConfig , reducers)
<a href="https://github.com/rt2zz/redux-persist/tree/v4.8.2" rel="nofollow">redux-persist v4</a>
<a href="https://github.com/rt2zz/redux-persist/tree/v4.8.2#persiststorestore-config-callback" rel="nofollow">persistStore</a> 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'] })