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.

Functions

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.

Interfaces

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.isSubmitting true, and on a thrown error surfaces a single root error via friendlyFetchError. Pair it with expectOk so API-level failures and network failures both become root errors through one code path. Returns the onSubmit handler to spread onto <form onSubmit={...}>.