VergeStackVergeStack

API Reference

useAction hook

This page provides detailed information about the parameters, return values, and types for the useAction hook.

Parameters

PropertyTypeDescription
actionGeneratedActionHandlerAn action created using the createAction function from @vergestack/api.
optionsUseActionOptions<OutputType>Optional configuration options for the useAction hook.

Return Value

The useAction hook returns an object with the following properties:

PropertyDescription
isPendingA boolean indicating whether the asynchronous operation is in progress.
isSuccessA boolean indicating whether the operation completed successfully.
isErrorA boolean indicating whether the operation resulted in an error.
errorsAn array of ApiErrorWithMetadata objects if the asynchronous operation fails.
dataThe data returned by the asynchronous operation.
statusThe HTTP status code of the response.
executeA function to manually trigger the execution of the asynchronous operation.
handlersAn object containing form action and onSubmit handlers for progressive enhancement.
getFormErrorA function to retrieve form-specific errors (useful for inline form errors).

Types

ApiResponse

type ApiResponse<T> = ApiResponseSuccess<T> | ApiResponseError;

ApiResponseSuccess

PropTypeDefault
status
ApiResponseSuccessCodes
-
data
NonNullable<T>
-
errors
never
-

ApiResponseError

PropTypeDefault
status
ApiResponseErrorCodes
-
data
never
-
errors
ApiError[]
-

ApiError

PropTypeDefault
message
string
-
reason
string
-

ApiResponseErrorCodes

import { StatusCodes } from 'http-status-codes';
 
type ApiResponseErrorCodes =
  | StatusCodes.BAD_REQUEST
  | StatusCodes.NOT_FOUND
  | StatusCodes.FORBIDDEN
  | StatusCodes.UNAUTHORIZED
  | StatusCodes.INTERNAL_SERVER_ERROR;

For more information on how to use these types and properties, refer to the Form Usage and Advanced Usage guides.

On this page