Whitelist reducer subproperty only?
See original GitHub issueIf I have an object on my state called purchases
and it has two properties, an array called ‘list’ and a boolean called ‘syncing’:
{
list: [],
syncing: false
}
Is there a way I can just whitelist my list
array like so?
persistStore(store, {
storage: AsyncStorage,
whitelist: [
`purchases.list`
]
});
It doesn’t seem to work.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:37
- Comments:10 (1 by maintainers)
Top Results From Across the Web
redux-persist - how do you blacklist/whitelist nested state
I want to persist the username but not the password. It might be that redux-persist only persists top-level state or it might be...
Read more >Storing a Single Sub-property with Redux-Persist - Medium
I recently ran across a need to persist just a single sub property for a given state key in ... [2] Whitelist reducer...
Read more >The Definitive Guide to Redux Persist - React Native Coach
Redux Persist takes your Redux state object and saves it to persisted storage. Then on app launch it retrieves this persisted state and...
Read more >Persist state with Redux Persist using Redux Toolkit in React
In the code above, we replaced the value of the reducer property ... When using blacklist and whitelist , we can only target...
Read more >Persisting state with Redux-Persist. | by Thinley Norbu
So what if we want to persist certain data of state only? ... like whitelist and blacklist in persistConfig while wrapping reducer.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dwilt @icesyc With redux-persist v5,
transforms
should be passed to persistConfig parameter of eitherpersistCombineReducers
orpersistReducer
. Like this:@dwilt @rt2zz
I came up with a 9-line solution that uses
redux-persist
without any other dependencies. Create a filepersist.js
with the following contents:You can now whitelist specific fields on any reducer. When creating reducers, you can export the reducer as usual if it doesn’t need to persist any keys, but you can use the function defined above to declare which fields to persist, and specify a unique key for the reducer in AsyncStorage. For instance, you can persist entire reducers in your root reducer, e.g.:
But you can also specify only specific keys at reducers at any depth:
I hope this helps anyone researching this particular issue. I have implemented this with Flow typings in practice. If anyone is interested in that, feel free to reach out.