# useShipping
# Features
useShipping
composable can be used for:
- Loading shipping address for the current cart.
- Saving shipping address for the current cart.
# API
load
- function for fetching shipping address. When invoked, it requests data from the API and populatesshipping
property.save
- function for saving shipping address. This method accepts a singlesaveParams
object. ThesaveParams
has the following options:shippingDetails: Address
type AgnosticAddress = {
firstName?: string;
lastName?: string;
streetName?: string;
apartment?: string;
city?: string;
state?: string;
postalCode?: string;
country?: string;
phone?: string;
};
shipping: AgnosticAddress
- a main data object that contains a shipping address.loading: boolean
- a reactive object containing information about loading state of yourload
orsave
method.error: UseShippingErrors
- a reactive object containing the error message, ifload
orsave
failed for any reason.
interface UseShippingErrors {
load?: Error;
save?: Error;
}
# Getters
We do not provide getters for checkout and its parts.
# Example
import { useShipping } from '@vue-storefront/sfcc';
import { onSSR } from '@vue-storefront/core';
export default {
setup () {
const { load, shipping } = useShipping();
onSSR(async () => {
await load();
});
return {
shipping
};
}
}