卸载表单后如何将状态保持在 redux 表单中
How do I keep the state in the redux form after I unmounted the form
我有一个基于架构呈现多个表单的组件,问题是我将更改架构,我将重新呈现表单,并且状态无法保留。
代码如下所示:
{schemas.map(schema => (
<div key={schema.$id}>
<h3 id={schema.$id}>
{schema.title}
</h3>
// a library using the redux form to keep the state.
<Liform
schema={schema}
onSubmit={value => console.log(`Submit ${JSON.stringify(value)}`)}
{...rest}
/>
</div>
))}
当我更改模式时,所有这些表单都将重新呈现,因此我无法保持具有相同 formName 的表单的状态,我该怎么做?
基于redux-form api你可以传递一个道具
destroyOnUnmount={false}
给你表单组件。或者在你的 reduxForm() 初始化
我自己用过它,它使表单状态保持在 re-render
https://redux-form.com/7.2.3/docs/api/reduxform.md/#-code-destroyonunmount-boolean-code-optional-
我有一个基于架构呈现多个表单的组件,问题是我将更改架构,我将重新呈现表单,并且状态无法保留。
代码如下所示:
{schemas.map(schema => (
<div key={schema.$id}>
<h3 id={schema.$id}>
{schema.title}
</h3>
// a library using the redux form to keep the state.
<Liform
schema={schema}
onSubmit={value => console.log(`Submit ${JSON.stringify(value)}`)}
{...rest}
/>
</div>
))}
当我更改模式时,所有这些表单都将重新呈现,因此我无法保持具有相同 formName 的表单的状态,我该怎么做?
基于redux-form api你可以传递一个道具
destroyOnUnmount={false}
给你表单组件。或者在你的 reduxForm() 初始化
我自己用过它,它使表单状态保持在 re-render
https://redux-form.com/7.2.3/docs/api/reduxform.md/#-code-destroyonunmount-boolean-code-optional-