Skip to main content
The useCheckoutAction hook enables interactions with checkout actions in a type-safe manner, automatically updating the checkout session upon successful execution.

Action Types

The hook supports various action types including:
  • ADD_ITEMS - Add items to the cart
  • REMOVE_ITEMS - Remove items from the cart
  • UPDATE_COUPONS - Update coupon codes
  • UPDATE_CUSTOMER_DETAILS - Update customer information
  • UPDATE_ITEMS_QUANTITY - Update quantities of items in the cart
  • UPDATE_SHIPPING_PACKAGES - Update shipping packages
  • UPDATE_SHIPPING_ADDRESSES - Update shipping addresses
  • UPDATE_PAYMENT_METHODS - Update payment methods
  • UPDATE_GIFT_CARDS - Apply or update gift cards
  • UPDATE_CUSTOMER_PREFERENCES - Update customer preferences (e.g. save data, locale)
  • SIMULATE_SESSION - Simulate a checkout session without mutating the real one
  • CREATE_ORDER - Create a new order
  • REQUEST - Make custom API requests to the backend

Parameters

  • actionType: ActionType - The type of checkout action to perform (e.g., ADD_ITEMS, REMOVE_ITEMS, etc.)
  • callback?: object - Optional configuration callbacks
    • onSuccess?: (data?: CheckoutSession, input?: Input) => void - Called when the action succeeds. Receives the updated session (or the order for CREATE_ORDER; unknown for REQUEST) and the input that was executed
    • onError?: ({ serverError, validationErrors }) => void - Called when action fails

Return Value

Returns an object with:
  • execute: (input: Input) => void - Function to dispatch the action with the appropriate payload
  • executeAsync: (input: Input) => Promise<Result | undefined> - Async version of execute that returns a Promise with the action result
  • isPending: boolean - Boolean indicating if the action is currently processing
  • error?: object - Error information if the action failed
    • serverError?: ServerError - Error returned by the server
    • validationErrors?: ValidatorErrors<Input> - Input Validation errors

Input Parameters by Action Type

Each action type expects specific input parameters. Below are the details for each:
Navigate the tabs to see details of each action

ADD_ITEMS

Example

Import

Usage

Action

Using executeAsync