Can't get ant design field decorator to work on itself

Viewed 89

Using ant design 4. New to the framework. Wondering why the below code doesn't work:


return (
    <Form
      initialValues={{ foo: 1 }}
      form={form}
      onFinish={onFinish}
    >
      <Form.Item dependencies={['foo']}>
      {({getFieldValue,setFieldsValue}) => {
          return (
            <button
              type="button"
              onClick={() => {
                setFieldsValue({ foo: getFieldValue('foo') + 1 });
              }}
            >
              Click Me {getFieldValue('foo')}
            </button>
          );
      }}
      </Form.Item>
    </Form>
)

Obviously I'm misunderstanding something about the way ant design forms work. My actual use case is very similar - I need to render a component that accepts an onClick and updates the form.

What am I misunderstanding here? Is there any way to make something like this work?

1 Answers
Related