react-component / form

React High Order Form Component(web & react-native)
http://react-component.github.io/form/
MIT License
1.81k stars 295 forks source link

why the getFieldValue return value is not initialValue ? #539

Open panpan-ren opened 2 years ago

panpan-ren commented 2 years ago

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>
  );
};