Last active
June 9, 2020 13:22
-
-
Save jucian0/aa979905723b7172ff5ec001370499ee to your computer and use it in GitHub Desktop.
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
const initialValues = { | |
name:"Jesse", | |
email:"jesse@jesse.com", | |
pets:["felix"], | |
accept:false | |
} | |
const validation = yup.object().shape({ | |
name: yup.string().required("This field is required"), | |
email: yup.string().email("This field must be a valid e-mail").required("This field is required"), | |
pets: yup.array(yup.string().required("This field is required")), | |
accept:yup.bool().oneOf([true], 'Field must be checked') | |
}) | |
function ControlledForm(){ | |
const [{values, reset},{input}] = useForm({debounce:300, initialValues, validation}) | |
return ( | |
<> | |
<input {...input("name", "text")}/> | |
<span>{touched.name && errors.name}</span> | |
<input {...input("email" ,"email")}/> | |
<span>{touched.email && errors.email}</span> | |
<input {...input("pets.0" ,"text")}/> | |
<span>{touched.pets?.[0] && errors.pets?.[0]}</span> | |
<input {...input("accept", "checkbox")}/> | |
<span>{touched.accept && errors.accept}</span> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment