Skip to main content

useCheckoutMutation

The useCheckoutMutation hook is a specialized wrapper around useMutation that provides methods for the multi-step checkout process. It coordinates between cart data and account-level data (like saved addresses) to ensure that the checkout flow remains synchronized.

import { useCheckoutMutation } from 'shop/client/features/cart/hooks/useCheckoutMutation';

const { setDeliveryMode, createDeliveryAddress, isCheckoutLoading } = useCheckoutMutation(options);

Parameters

NameTypeRequiredDescription
optionsMutateOptionsStandard options for the useMutation hook.

options

Standard mutation options. See MutateOptions for more information.

Return value

PropertyTypeDescription
createDeliveryAddress(address: DeliveryAddress) => Promise<void>Creates a new delivery address for the cart.
setDeliveryMode(mode: string) => Promise<void>Sets the shipping/delivery method.
setPaymentMode(data: PaymentData) => Promise<void>Sets the payment method.
isCheckoutLoadingbooleanTrue if a checkout step is in progress.
isCheckoutErrorbooleanTrue if a checkout step failed.
resetCheckoutErrorFunctionClears the error state.

Example

import { useCheckoutMutation } from 'shop/client/features/cart/hooks/useCheckoutMutation';

function ShippingMethods({ modes }) {
const { setDeliveryMode, isCheckoutLoading } = useCheckoutMutation();

const handleSelect = async (mode) => {
await setDeliveryMode(mode.code);
};

return (
<div>
{modes.map(mode => (
<button
key={mode.code}
onClick={() => handleSelect(mode)}
disabled={isCheckoutLoading}
>
{mode.name}
</button>
))}
</div>
);
}