React-Hook-form 3: Controller, useController(), useformState() and form Context.
//All validate will be triggered on submit.
const {register, handleSubmit} = useForm()
const valori = (data) => {console.log( "formData:", data )}
const sbagli = (errori) => {console.log( "Returned validate errors:", errori )}
<form onSubmit={handleSubmit(valori, sbagli)}>
<input {...register("primo", {
validate: (value)=>{ return value.length > 5 && "Validate error" }
})}/>
<input {...register("secondo", {
maxLength: { value: 4, message: "Built-in error" }
})}/>
</form>The <Controller> input component.
The useController() custom hook.
The useFormContext() and <FormProvider> component.
The useFormState() custom hook.
PreviousReact-hook-form 2: trigger() validate, errors, values and formState methods.NextThe fieldArray structure and methods on useForm()
Last updated