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 cartREMOVE_ITEMS
- Remove items from the cartUPDATE_COUPONS
- Update coupon codesUPDATE_CUSTOMER_DETAILS
- Update customer informationUPDATE_ITEMS_QUANTITY
- Update quantities of items in the cartUPDATE_SHIPPING_PACKAGES
- Update shipping packagesUPDATE_SHIPPING_ADDRESSES
- Update shipping addressesUPDATE_PAYMENT_METHODS
- Update payment methodsCREATE_ORDER
- Create a new order
Parameters
actionType: ActionType
- The type of checkout action to perform (e.g.,ADD_ITEMS
,REMOVE_ITEMS
, etc.)callback?: object
- Optional configuration callbacksonSuccess?: (data?: CheckoutSession) => void
- Called when action succeedsonError?: ({ 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 payloadisPending: boolean
- Boolean indicating if the action is currently processingerror?: object
- Error information if the action failedserverError?: ServerError
- Error returned by the servervalidationErrors?: 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