web / useAddress
Function: useAddress() ​
useAddress(
type
,cacheKey
?):UseAddressMethods
Defined in: apps/web/composables/useAddress/useAddress.ts:47
Parameters ​
type ​
AddressType
cacheKey? ​
string
Returns ​
Deprecated ​
use useAddressStore
, useCheckoutAddress
, useCreateAddress
, usePrimaryAddress
, useFetchAddress
, useDeleteAddress
instead
Description ​
Composable for working with addresses in the current user session. The composable covers two types of addresses, billing and shipping.
Example ​
This example uses the address type Billing
. All examples are equivalent for addresses of type Shipping
.
ts
const {
data,
loading,
defaultAddressId,
savedAddress,
getAddresses,
saveAddress,
deleteAddress,
setDefault
} = useAddress(AddressType.Billing);
let address: Address;
let id: Number;
getAddresses();
saveAddress(address);
deleteAddress(id);
setDefault(id);
getAddresses
gets all addresses of the address type passed touseAddress
. UpdatesdefaultAddressId
to the current default address.saveAddress
saves the given address with the address type passed touseAddress
. If successful, it returns thesavedAddress
. After saving the address, updates the list of addresses.deleteAddress
deletes the address of the address type passed touseAddress
with the given ID. After deleting the address, updates the list of addresses.setDefault
updates thedefaultAddressId
of the type passed touseAddress
with the given ID. After setting the default, updates the list of addresses.