0

我试图将我的 redux 存储持久化到 sessionStorage,并且我希望一个减速器不要持久化。我试图将其名称添加到黑名单数组中,但它仍然保留整个商店。你们能告诉我配置中的键是什么吗?在文档中它显示如下

{
 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
}
4

2 回答 2

1

它指的是您的子减速器键,但深度一级(这可能是您的问题)。

一个例子

你像这样创建你的主减速器

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

如果你只想持久化你的commentsreducer,你可以使用whitelist: ['comments']or blacklist: ['app', 'auth']。如果你想将更深层次的东西列入黑名单或白名单,你应该看到 redux-persist-transform-filter。

于 2018-05-23T09:23:09.683 回答
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,
});
于 2020-03-01T06:13:08.157 回答