Gives every form that posts to the API the same submit, which shows a failed
request as the form's root error. It is react-hook-form's useForm plus that
submit.
f
useApiForm<T extends FieldValues>(options?: UseFormProps<T>): UseApiFormResult<T>
Returns a react-hook-form form made with options, plus submit, which
turns a failed request into the form's root error.
I
UseApiFormResult
Returned by useApiForm, the form with submit added.
-
submit: (handler: SubmitHandler<T>) => (e?: React.BaseSyntheticEvent) => Promise<void>
Wraps an async submit handler with the shared API-form lifecycle: clears the previous root error, runs the handler while RHF keeps
formState.isSubmittingtrue, and on a thrown error surfaces a single root error viafriendlyFetchError. Pair it withexpectOkso API-level failures and network failures both become root errors through one code path. Returns theonSubmithandler to spread onto<form onSubmit={...}>.
Usage
import * as mod from "src/hooks/form/useApiForm.ts";