嗨,在我们的应用程序中,我们有一个 reducer 模式:
{
data: //here we have our actual data
fetching: // is it still fetching
intact: // has it been 'touched'
error: //errors if need be
}
此外,由于业务需求,我需要保留一个 ReduxForm,它本身就是一堆蠕虫……
form: {
Foobar: {
values: {
},
initial: {
},
syncErrors: {
},
registeredFields: {
}
}
}
}
正如您可能已经发现的那样,除了数据之外,持久化任何东西都是没有意义的,但是 Redux-Persist 会持久化整个 reducer。关于过滤和转换的例子有点……我觉得乏善可陈,我一直在努力实现。寻找一个例子
最佳答案
好的,所以这可以使用 redux-persist-transform-filter 像@NickHTTPS sugested:
import createFilter from 'redux-persist-transform-filter';
const saveSubsetFilter = createFilter('form', ['Foo.bar']);
const persistConfig = {
key: 'form',
storage,
whitelist: ['form'],
transforms: [saveSubsetFilter]
};
persistCombineReducers(persistConfig, { form: formReducer });
就像一个魅力:)
关于javascript - 仅保留 Reducer 中的某些字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52161050/