form icon indicating copy to clipboard operation
form copied to clipboard

why the getFieldValue return value is not initialValue ?

Open panpan-ren opened this issue 3 years ago • 0 comments

I am a fan of ant-design.As the usage scenarios in business projects gradually increase, I find the getFieldValue function are not quite smart.The getFieldValue function will return undefined when render component, even though we set an initialValue props in a FormItem component.

I don't know why it's set like this,is there a reason this case?

Code example:

const App = () => {
  const [form] = Form.useForm();
  const name = form.getFieldValue("name");
  console.log(name); // undefined

  return (
    <Form {...layout} form={form} name="control-hooks">
      <Form.Item
        name="name"
        label="Name"
        initialValue="test"
        rules={[{ required: true }]}
      >
        <Input />
      </Form.Item>
    </Form>
  );
};

panpan-ren avatar Aug 18 '22 08:08 panpan-ren