Last active
March 12, 2020 21:21
-
-
Save zant/7047e91bc535a6711d84344b0f4dd957 to your computer and use it in GitHub Desktop.
AntD with react-hook-form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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