Skip to content

useActionForm

Overview

Provides submit, cancel, and dry-run behaviour for action forms. Pass the injected form context and a reactive props-compatible object. ActionForm calls this internally; use it directly when you want the logic without the ActionForm shell.

When the server gates the action behind warning acknowledgement (HTTP 409, surfaced as a ConfirmationRequiredError with a digest), the returned confirmation controller prompts the user and a confirmed action is retried once with the digest acknowledged. ActionForm mounts the FormConfirmDialog bound to the controller; standalone callers must render one (or register a custom consumer), otherwise warned submissions fail closed as cancelled.

Signature

useActionForm(formContext, props)

Parameters

NameTypeRequiredDescription
formContextFormContextyesThe form context providing validation state.
propsobjectyesReactive action form configuration.

props Properties

NameTypeRequiredDefaultDescription
actionErrorSummarystringToast text on failure.
actionStateobjectAction execution status.
actionSuccessSummarystringToast text on success.
dryRunTargetstringIdentity of the current dry-run target. A value different from the last run's target permits another automatic validation pass once readyToDryRun is true, including when returning to a previously validated target. Omit it for a caller with no target concept; automatic validation then runs at most once per useActionForm instance, even if readiness toggles.
fetchStateobjectData-fetch status.
hasInputbooleanWhether the form has input fields that must be validated before submission.
onSubmissionErrorHandler(args: object) => PromiseReplaces the default error toast.
onSubmissionSuccessHandler(response: any) => voidReplaces the default success toast and redirect.
onSubmissionWarningsRequireConfirmation(options: object) => PromiseReplaces the default handling of a confirmation-required response (HTTP 409): render the warnings and ask the user via the confirmation controller. Resolving true retries the action once with the warnings acknowledged.
readyToDryRunbooleanWhen true, permits the first automatic dry-run validation pass and another pass when dryRunTarget differs from the last run's target. Toggling readiness off and on does not repeat validation for the same target.
redirectTo(reason: "cancel" | "success") => PromiseCalled after success or cancel.
requireModifiedbooleanWhen false, skips the "no changes detected" guard. Defaults to true. Set to false for forms that start empty (sign-in, forgot-password) where modification is not a meaningful concept.
runAction(options: object) => PromiseExecutes the action. acknowledgeWarnings carries the warnings digest of a confirmed retry; implementations should forward it as the Acknowledge-Warnings header (see useModelAction).

Returns

ActionFormContext

Source

client/lib/use/useActionForm.js:89

Documents matching: server v3.0.0a1.post1client v3.0.0-alpha.2