Redux-persist: Whitelisting Specific Parts of State

Created on 1 Apr 2017  路  8Comments  路  Source: rt2zz/redux-persist

My Redux state is a multi-level tree. Is there a way for me to whitelist just key A.X instead of the entirety of A?

stale

Most helpful comment

Currently there are three ways to achieve this:

  • implement a custom REHYDRATE handler in your reducer which skips the keys you dont want to persist
  • use https://github.com/edy/redux-persist-transform-filter to achieve the same effect ^
  • refactor your reducer to store non-persisted state in different reducer than persisted state

Best solution I think depends on the specifics of your app.

All 8 comments

Yes I also have a multi-level tree like

entities: {
   users: {},
   posts: {},
   typing:{},
   ...
},
requests: {...}

How can I just blacklist entities.typing?

+1

Currently there are three ways to achieve this:

  • implement a custom REHYDRATE handler in your reducer which skips the keys you dont want to persist
  • use https://github.com/edy/redux-persist-transform-filter to achieve the same effect ^
  • refactor your reducer to store non-persisted state in different reducer than persisted state

Best solution I think depends on the specifics of your app.

Yeah I think im going to go with the filter. Thanks

is there some example of custom REHYDRATE hadnler?

@FilipMessa It's as simple as just handling REHYDRATE action in ur reducer which you can import from 'redux-persist/constants'

This hasn't been responded to in a long while, so I'm going to mark it as stale. Please feel free to continue the conversation and I'll reopen.

Was this page helpful?
0 / 5 - 0 ratings