Created
October 21, 2021 15:34
-
-
Save VithuJey/1f61f97b35aa52094e855e81c1b0d9c3 to your computer and use it in GitHub Desktop.
Just a gist to explain React Hook Form (RHF)
This file contains 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
export default function DeliveryForm() { | |
const { register, handleSubmit, formState: { errors } } = useForm(); | |
const onSubmit = data => console.log(data); | |
return ( | |
<form onSubmit={handleSubmit(onSubmit)}> | |
<input placeholder="Full Name" {...register("fullName")} /> | |
<input placeholder="Delivery Address" {...register("deliveryAddress", { required: true })} /> | |
{errors.deliveryAddress && <span>Delivery Address is required</span>} | |
<button type="submit">Review Order</button> | |
</form> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment