React native + redux-persist:如何忽略键(黑名单)? [英] React native + redux-persist: how to ignore keys (blacklist)?
问题描述
我正在使用 redux-persist
存储我的设置,并希望忽略其中的一些设置,以便在每次重新启动时重置它们,例如崩溃后.
I'm storing my settings with redux-persist
and would like to ignore some of them to have them reset on every restart, e.g. after a crashing.
可以将一个 reducer-name 数组添加为 blacklist
或 whitelist
,但我想忽略特定的键,例如settings.isLoggedIn
而不是 settings
.
It's possible to add an array of reducer-names as blacklist
or whitelist
, but I'd like to ignore specific keys, e.g. settings.isLoggedIn
instead of settings
.
// ...
function configureStore(initialState) {
const store = createStore(
RootReducer,
initialState,
enhancer
);
persistStore(store, {
storage: AsyncStorage,
blacklist: ['router', 'settings'] // works, 'settings.isLoggedIn' doesn't.
}, () => {
// restored
});
return store;
}
// ...
我是否必须创建另一个减速器或是否有人解决此问题?
Do I have to create another reducer or does anyone a solution to this problem?
提前致谢!
推荐答案
根据 文档,黑名单参数包含:要忽略的键(读取:reducers)",因此恐怕无法实现您想要的行为.您可以尝试自己实现该功能,但我认为该包的代码库真正侧重于将减速器而不是属性列入黑名单(请参阅 this).恐怕唯一的解决方案是为您的非持久键创建一个单独的减速器(根据我的经验,这并不麻烦).
As per the documentation, the blacklist parameter contains: 'keys (read: reducers) to ignore', so I am afraid it is not possible to implement the behaviour that you want. You can try and implement that functionality yourself, but I think the codebase of the package is really focused on blacklisting reducers instead of properties (see this). I am afraid that the only solution is to create a separate reducer for your non-persistent keys (in my experience it is not much of a hassle).
这篇关于React native + redux-persist:如何忽略键(黑名单)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!