Skip to content

selectSelectedShipping$(): Observable<BasketShipping | undefined>

The selectSelectedShipping$ method allows you to observe the currently selected shipping option.

Returned value

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

Example

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

useStorefront(async (storefront) => {
    let basketShippingsApi = storefront.getApiSync('basketShippingsApi');

    if (!basketShippingsApi) {
        const featureSystemApi = this.getApiSync(FEATURE_SYSTEM_API_NAME);
        await featureSystemApi.registerDynamic('basket');

        basketShippingsApi = storefront.getApiSync('basketShippingsApi');
    }

    const selectedShipping$ = basketShippingsApi.selectSelectedShipping$();

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

Basket Address API methods reference

Models reference