web / useAddress
Variable: useAddress ​
constuseAddress:UseAddressReturn
Defined in: apps/web/app/composables/useAddress/useAddress.ts:47
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);getAddressesgets all addresses of the address type passed touseAddress. UpdatesdefaultAddressIdto the current default address.saveAddresssaves the given address with the address type passed touseAddress. If successful, it returns thesavedAddress. After saving the address, updates the list of addresses.deleteAddressdeletes the address of the address type passed touseAddresswith the given ID. After deleting the address, updates the list of addresses.setDefaultupdates thedefaultAddressIdof the type passed touseAddresswith the given ID. After setting the default, updates the list of addresses.