Xer*_*ero 4 reactjs final-form react-final-form react-final-form-arrays
我的代码正在运行,但收到警告:
警告:从 React Final Form v3.3.0 开始,props.mutators 已被弃用,并将在 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>
)
}}
/>
Run Code Online (Sandbox Code Playgroud)
怎么做才是正确的?
小智 6
警告已经告诉你该怎么做。
您必须使用form.mutators而不仅仅是mutators
为此,您可以将代码从
mutators: { push, pop }
Run Code Online (Sandbox Code Playgroud)
到
form: { mutators: { push, pop } }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1481 次 |
| 最近记录: |