Skip to content

Instantly share code, notes, and snippets.

@Luchanso
Created June 17, 2021 14:56
Show Gist options
  • Save Luchanso/724ba83a2007bada92eae3d62f17c9d3 to your computer and use it in GitHub Desktop.
Save Luchanso/724ba83a2007bada92eae3d62f17c9d3 to your computer and use it in GitHub Desktop.
const schema = yup.object().shape({
email: yup.string().required("is requeried").email("missing email"),
// age: yup.number().positive().integer().required(),
});
export default function FieldEmail() {
const {
register,
formState: { errors },
} = useFormContext();
return (
<>
<input
{...register("email", {
validate: (email) => schema.validate({ email }).catch((e) => e.errors[0]),
})}
/>
<br />
<span>{errors.email && errors.email.message}</span>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment