props.mutators is deprecated



我的代码正在工作,但我收到了一个警告:

警告:自React Final Form v3.3.0起,props.mutator已被弃用并将在React Final Form的下一个主要版本中删除。请改用:props.form.mutators。检查ReactFinalForm渲染道具

以为例

https://codesandbox.io/s/kx8qv67nk5

return   <Form
onSubmit={() => console.log('ok')}
mutators={{
...arrayMutators
}}
initialValues={ {customers: [{firstName: 'a', lastName: 'b'}]} }
render={({
handleSubmit,
mutators: { push, pop }, // injected from final-form-arrays above
pristine,
reset,
submitting,
values
}) => {
return (
<form onSubmit={handleSubmit}>
<div className="buttons">
<button
type="button"
onClick={() => push('customers', undefined)}>
Add Customer
</button>
</div>
<FieldArray name="customers">
{({ fields }) =>
fields.map((name, index) => (
<div key={name}>
<label>Cust. #{index + 1}</label>
<Field
name={`${name}.firstName`}
component="input"
placeholder="First Name"
/>
<Field
name={`${name}.lastName`}
component="input"
placeholder="Last Name"
/>
<GithubField name="user1" onSearch={(item) => {
this.api.getByFirstname(item).then(result => console.log(result));
}} />
<span
onClick={() => fields.remove(index)}
style={{ cursor: 'pointer' }}>❌</span>
</div>
))}
</FieldArray>
<div className="buttons">
<button type="submit" disabled={submitting || pristine}>
Submit
</button>
<button
type="button"
onClick={reset}
disabled={submitting || pristine}>
Reset
</button>
</div>
<pre>{JSON.stringify(values, 0, 2)}</pre>
</form>
)
}}
/>

如何做正确的方式?

警告已经告诉了你该怎么做。

您必须使用form.mutators而不是仅使用mutators

为此,您可以从更改代码

mutators: { push, pop }

form: { mutators: { push, pop  } }

相关内容

  • 没有找到相关文章