Skip to content

Instantly share code, notes, and snippets.

@haldarmahesh
Last active April 12, 2020 07:10
Show Gist options
  • Save haldarmahesh/a8dc5592dc8d2acca8aa2284b0bff052 to your computer and use it in GitHub Desktop.
Save haldarmahesh/a8dc5592dc8d2acca8aa2284b0bff052 to your computer and use it in GitHub Desktop.
import React from "react";
import { useForm } from "react-hook-form";
function onSubmitForm(formData) {
console.log("The status of formData", formData);
alert("Hi your phone number is: " + formData.phoneNumber);
}
export default function MyForm() {
const { register, handleSubmit, errors } = useForm();
console.log("ERR", errors);
return (
<form onSubmit={handleSubmit(onSubmitForm)}>
<label>
Phone Number:
<input
type="text"
name="phoneNumber"
ref={register({ required: true, minLength: 12 })}
/>
</label>
<input type="submit" value="Submit" />
</form>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment