如何从 redux-persist 中删除一个减速器

dnm*_*nmh 3 reactjs redux

我继承了一个使用 redux-persist 并具有多个减速器的项目。我为一个小功能编写了一个新的减速器,并坚持认为减速器导致了问题。它的行为应该与没有 redux-persist 时一样。

我怎样才能从持久化中忽略一个减速器?或者,如果我不能,我该如何手动清除它?在文档中,这里: https: //github.com/rt2zz/redux-persist,我发现了这个:

persistor object
  the persistor object is returned by persistStore with the following methods:
    .purge(keys)
      keys array An array of keys to be purged from storage. If not provided all keys will be purged.
    ...
Run Code Online (Sandbox Code Playgroud)

所以,这可能就是我需要的,但我不知道在哪里以及如何使用它。

zer*_*ain 8

您可以使用该blacklist参数给出react-persist不应存储的减速器列表。因此,如果do-not-store是您不想存储的减速器的键,请使用:

const persistConfig = {
  blacklist: ['do-not-store'],
  ...
}

persistStore(store, persistConfig)
Run Code Online (Sandbox Code Playgroud)