19952

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'] })

Recommend

  • Redux saga - Worker saga not getting called on react native
  • How to add Redux DevTools Extension to my react-redux store?
  • React-Redux componentWillReceiveProps not triggered using api data
  • Hive command line Select query time taken incorrect if its not map reduce job in the background
  • Change state's array without changing the whole state (REACT / REDUX)
  • reducers get Function not Object in redux, what's wrong with it?
  • Hadoop shuffle uses which protocol?
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • Getting media player state in windows phone 7
  • Lock Horizontal View
  • Is there a way to save the selected text and highlight it again once the page is refreshed?
  • Debugging VB6 Code From Visual Studio 2010
  • Build Successful but not running on simulator
  • How to assign byte[] as a pointer in C#
  • Button text different than value submitted in query string
  • Using JRuby with Rails 3.2
  • Code in Job's Script Block after Start-Process Does not Execute
  • Calling Worksheet functions from vba in foreign language versions of Excel
  • Get history of file changes from TFS to implement custom “blame”-behaviour of exceptions
  • Do I need to reset a Perl hash index?
  • iOS: Detect app start via notification press
  • Meteor helpers not available in Angular template
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Is calc() supported in html email?
  • req.body is undefined - nodejs
  • Accessing IRQ description array within a module and displaying action names
  • AES padding and writing the ciphertext to a disk file
  • VS2008 Enable C++ Exception with SEH
  • Obtain ObjectIdHex value from mgo query
  • javascript inside java/jsp code
  • Javascript Callbacks with Object constructor
  • Where to put my custom functions in Wordpress?
  • Symfony2: How to get request parameter
  • Akka Routing: Reply's send to router ends up as dead letters
  • Is there a mandatory requirement to switch app.yaml?
  • Comma separated Values
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET