How to fix it
Warning: Cannot use
setFieldsValue
until you usegetFieldDecorator
orgetFieldProps
to register it.
I faced the same issue with react hooks. Following solution works for me.
props.form.getFieldDecorator('Amount', { initialValue: 'My Value' })
As I feel the reason is initialValue is not going to change after the first render, just like defaultValue.
From the doc https://ant.design/components/form/#this.props.form.getFieldDecorator(id,-options):
After wrapped by getFieldDecorator, value(or other property defined by valuePropName) onChange(or other property defined by trigger) props will be added to form controls,the flow of form data will be handled by Form [...]
So, without the registration of the form field with getFieldDecorator
, you cannot use setFieldsValue
.
You are setting a value to a field that doesn't exist inside the form.
First, you must register the field into the form with getFieldDecorator
and then you can use the setter.
Maybe the getter-style method name it's a bit misleading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With