redux-persist v5配置的黑名单和白名单中有哪些键?

时间:2017-11-01 15:55:17

标签: javascript reactjs redux redux-persist

我试图将我的redux商店保存到sessionStorage,我希望一个reducer不会持久存在。我试图在黑名单数组中添加它的名字,但它仍然存在整个商店。 你能告诉我配置中的键是什么吗? 在文档中它显示如下

{
 key: string, // the key for the persist
 storage: Object, // the storage adapter, following the AsyncStorage api
 version?: number, // the state version as an integer (defaults to -1)
 blacklist?: Array<string>, // do not persist these keys
 whitelist?: Array<string>, // only persist they keys
 migrate?: (Object, number) => Promise<Object>,
 transforms?: Array<Transform>,
 throttle?: number,
 keyPrefix?: string, // will be prefixed to the storage key
 debug?: boolean, // true -> verbose logs
 stateReconciler?: false | StateReconciler, // false -> do not 
 automatically reconcile state
}

2 个答案:

答案 0 :(得分:0)

它指的是你的减速器键,但是深一层(它可能是你的问题)。

例子

您可以像这样创建主减速器

export default combineReducers({
  app,
  auth,
  comments
});

如果您只想保留comments缩减器,可以使用whitelist: ['comments']blacklist: ['app', 'auth']。 如果你想将更深层次列入黑名单或列入白名单,你应该看到redux-persist-transform-filter。

答案 1 :(得分:0)

您在redux中的index.js应该是这样的:

import {persistCombineReducers} from 'redux-persist';
import storage from 'redux-persist/es/storage';

// You have to import every reducers and combine them.
import {reducer as UserReducer} from './UserReducer';
import {reducer as CommentReducer} from './CommentReducer';
import {reducer as ProductRedux} from './ProductRedux';

const config = {
  key: 'root',
  storage,
  blacklist: [
    'Comment',
    'Product',
  ],
};

export default persistCombineReducers(config, {
  user: UserReducer,
  comment: CommentReducer,
  product: ProductRedux,
});