rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.91k stars 863 forks source link

Nested configs are no longer necessary #1371

Open PiotrKujawa opened 2 years ago

PiotrKujawa commented 2 years ago

Hi everyone, I'd like to introduce a new possibility in creating Redux Persist config using my package called Redux Deep Persist. Nested configs are no longer necessary because you can use getPersistConfig method and define a nested whitelist or a blacklist using dot notation: whitelist: ['key1.nestedProp1.nestedProp2.nestedProp3', ...'] or blacklist: ['key1.nestedProp1.nestedProp2.nestedProp3', ...'].

Here's an example of configuration:

import { getPersistConfig } from 'redux-deep-persist';

const config = getPersistConfig({
    key: 'root',
    storage: AsyncStorage, // whatever storage you use
    whitelist: [
        'property1.a1.b1',  
        'property1.a2.b2.c2', // no matter how deep you go
        'property2.a2',
    ],
    rootReducer, // your root reducer must be also passed here
    ... // any other props from original redux-persist config omitting the stateReconciler
})

My proposal is to add that note to the official documentation of Redux Persist as an alternative method of configuration. I've seen lots of questions about "how to persist nested state", and because I had the same requirement in my own project I decided to make our life easier. Please let me know what do you think. I hope this will be helpful.

@rt2zz @ckalika please take a look. Thanks.

ckalika commented 2 years ago

Hey there, @PiotrKujawa. Thanks for this I'll take a look and come back to you shortly. :)

liquidvisual commented 2 years ago

@PiotrKujawa Thank you for creating this, it's so useful and well documented too!

PiotrKujawa commented 2 years ago

@liquidvisual I'm glad you found it useful :)