卸载组件后,redux-form 正在破坏我的状态,这是什么原因?
redux-form is Destroying my state once the component is unmounted, what gives?
我没有传递任何特殊的配置设置,也没有 setting/or 调用 Destroy...但是我的状态正在被清理...无论如何要防止这种情况发生?我需要状态保持不变,因为我需要整个应用程序中的数据。
prev state: I see it in there... via redux-logger
action: redux-form/Destroy
next state: it's gone.
您可能正在将 redux-forms
的状态合并到您的状态中,您应该将它放在单独的密钥下。 Destroy
操作 returns 未定义,这没关系,如果 redux-forms reducer 只管理它是商店的一部分。
确保您遵循本教程中的第 1 步,特别是 form: formReducer
部分:
https://redux-form.com/7.2.3/docs/gettingstarted.md/#step-1-of-4-form-reducer
窗体的状态子树 是 在卸载窗体时销毁的,这是设计使然。这是默认和预期的行为。
来自 v6.2.1 onwards there is a form config property destroyOnUnmount
, which explicitly enables/disables the state-clearing behaviour on a specific form (docs here)
import { reduxForm } from 'redux-form';
reduxForm({
form: 'example',
destroyOnUnmount: false
})(...)
如果您有一个表单,如果用户中途放弃它,导航离开,然后 returns 稍后,您希望保留其状态,这将很有用。
我没有传递任何特殊的配置设置,也没有 setting/or 调用 Destroy...但是我的状态正在被清理...无论如何要防止这种情况发生?我需要状态保持不变,因为我需要整个应用程序中的数据。
prev state: I see it in there... via redux-logger
action: redux-form/Destroy
next state: it's gone.
您可能正在将 redux-forms
的状态合并到您的状态中,您应该将它放在单独的密钥下。 Destroy
操作 returns 未定义,这没关系,如果 redux-forms reducer 只管理它是商店的一部分。
确保您遵循本教程中的第 1 步,特别是 form: formReducer
部分:
https://redux-form.com/7.2.3/docs/gettingstarted.md/#step-1-of-4-form-reducer
窗体的状态子树 是 在卸载窗体时销毁的,这是设计使然。这是默认和预期的行为。
来自 v6.2.1 onwards there is a form config property destroyOnUnmount
, which explicitly enables/disables the state-clearing behaviour on a specific form (docs here)
import { reduxForm } from 'redux-form';
reduxForm({
form: 'example',
destroyOnUnmount: false
})(...)
如果您有一个表单,如果用户中途放弃它,导航离开,然后 returns 稍后,您希望保留其状态,这将很有用。