UseFormSetError
Set an error for the field. When set an error which is not associated to a field then manual clearErrors
invoke is required.
@example
// when the error is not associated with any fields, `clearError` will need to invoke to clear the error
const onSubmit = () => setError("serverError", { type: "server", message: "Error occurred"})
<button onClick={() => setError("name", { type: "min" })} />
// focus on the input after setting the error
<button onClick={() => setError("name", { type: "max" }, { shouldFocus: true })} />
type UseFormSetError<TFieldValues extends FieldValues> = (
name: FieldPath<TFieldValues> | `root.${string}` | "root",
error: ErrorOption,
options?: {
) => void;shouldFocus: boolean;
},§Type Parameters
§
TFieldValues extends FieldValues
[src]§Type
§
(name: FieldPath<TFieldValues> | `root.${string}` | "root", error: ErrorOption, options?: {
[src]shouldFocus: boolean;
}) => void