Skip to content

Instantly share code, notes, and snippets.

@zant
Last active March 12, 2020 21:21
Show Gist options
  • Select an option

  • Save zant/7047e91bc535a6711d84344b0f4dd957 to your computer and use it in GitHub Desktop.

Select an option

Save zant/7047e91bc535a6711d84344b0f4dd957 to your computer and use it in GitHub Desktop.
AntD with react-hook-form
const Example = () => {
const { control, handleSubmit, errors } = useForm()
const onSubmit = data => console.log(data)
console.log(errors)
return (
<Form onSubmit={handleSubmit(onSubmit)}>
<Controller
name="email"
control={control}
rules={{ required: "Please enter your email address" }}
as={
<Form.Item
label="name"
validateStatus={errors.email && "error"}
help={errors.email && errors.email.message}
>
<Input />
</Form.Item>
}
/>
<Button htmlType="submit">Submit</Button>
</Form>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment