redux-persist icon indicating copy to clipboard operation
redux-persist copied to clipboard

How to persist a part of the store?

Open podeig opened this issue 7 years ago • 3 comments
trafficstars

Hi, Now I use Whitelist to persist just a part of the store like:

const persistConfig = { key: 'root', storage, whitelist: ['ui', 'communication'] };

but I need to persist just a part of UI, for example it could be like

const persistConfig = { key: 'root', storage, whitelist: ['ui.panels', 'ui.paddings', 'communication.list'] };

Is it any way to do this?

podeig avatar Aug 24 '18 10:08 podeig

set up several configs, each on a different key, see https://github.com/rt2zz/redux-persist#nested-persists

abenhamdine avatar Aug 24 '18 14:08 abenhamdine

Probably close this?!

hgezim avatar Dec 20 '19 01:12 hgezim

Here is what you can do using my package redux-deep-persist, which can be helpful in creating a redux-persist config.

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

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

PiotrKujawa avatar Mar 25 '22 15:03 PiotrKujawa