Skip to content

selectSelectedShippingCountry$(): Observable<ShippingCountry | undefined>

The selectSelectedShippingCountry$ method allows you to observe the currently selected shipping country.

Returned value

A returned value has a type of Observable<ShippingCountry | undefined> where ShippingCountry represents the ShippingCountry model.

Example

In this example, we make a basketShippingsApi call to observe the currently selected shipping country.

useStorefront(async ({ eventBus, getApi }) => {
    eventBus.on('basket.initialized', async () => {
        const basketShippingsApi = await getApi('basketShippingsApi');

        const selectedShippingCountry$ = basketShippingsApi.selectSelectedShippingCountry$();

        selectedShippingCountry$.subscribe((shippingCountry) => {
            if (shippingCountry) {
                console.log('Currently selected shipping country:', shippingCountry.name);
            } else {
                console.log('No shipping country is currently selected.');
            }
        });
    });
});

Basket Address API methods reference

Models reference