Skip to content

why the getFieldValue return value is not initialValue ? #539

@panpan-ren

Description

@panpan-ren

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions