如何停止 redux-form 的“表单"从 redux-persit 自动再水化状态 [英] How to stop redux-form's "form" state from auto-rehydrated by redux-persit

查看:23
本文介绍了如何停止 redux-form 的“表单"从 redux-persit 自动再水化状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 redux-form,它提供了一个名为formReducer"的内置 reducer,需要向组合的 reducer 注册以使用 redux 的存储管理表单状态.

I'm using redux-form and it provides a built-in reducer, called "formReducer" that need to be registered with the combined reducers to manage the form state with redux's store.

我也在使用 redux-persist 来持久化 redux 存储.

I'm also using redux-persist to persist the redux store.

当我不想让我的表单自动重新填充用户在页面重新加载或页面刷新时输入的数据时出现的问题.在我自己编写的普通 reducer 中,我可以简单地为REHYDRATE"类型的操作添加一个 switch case(由 redux-persit 调度),以防止状态切片通过返回其初始状态或空状态来自动重新水化.但是redux-form的formReducer是redux-form内置提供的,所以我无法更改.那么,有没有办法自定义"redux-form reducer 来添加那个 switch case?或者,有什么方法可以将 redux-persist 配置为不自动重新水合特定状态切片,或者有什么方法可以将 redux-form 配置为不通过页面重新加载或页面刷新自动填充?

The problem raised when I don't want to have my form automatically re-populate the data entered by the user on page reloading or page refreshing. In a normal reducer written by my own, I can simply add an switch case for action of type "REHYDRATE" (dispatched by redux-persit) to prevent the state slice from auto-rehydrating by just returning its initial state or an empty state. But redux-form's formReducer is built-in provided by redux-form, so I cannot change. So, is there any way to "customize" the redux-form reducer to add that switch case? Or, is there any way I can config redux-persist to not auto-rehydrate a specific state slice, or is there any way I can config redux-form to not being auto-populated by page reloading or page refreshing?

推荐答案

如果您使用的是最新的 (v5) redux-persist 版本,则在 persistConfig 选项中有一个白名单键选项,您可以在其中将哪些减速器列入白名单/再水化.你应该使用它,例如:

If you are using the latest (v5) redux-persist version, in the persistConfig option there's a whitelist key-option where you whitelist which reducers should be persisted/rehydrated. You should use that, e.g:

<代码>const persistConfig = {键:'root_key_in_localstorage',贮存,白名单:['会话'],}

这篇关于如何停止 redux-form 的“表单"从 redux-persit 自动再水化状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆