Skip to content

removeFlashMessage(id: string, containerName?: string): void;

The removeFlashMessage method removes a flash message from the given flash messenger if it exists.

Input parameters

id

id is a mandatory parameter of type string which represents the id of the flash message to remove.

containerName (optional)

string is a mandatory parameter that tell the api which flash-messenger should it refer to. If not specified the message will be removed from the global flash messenger if it exists inside it.

Event Bus events

This API method dispatches the following events with the Event Bus:

Example

Making a Flash Messages API call to add and then remove a flash message with a given id from a Flash Messenger webcomponent with the name="my-flash-messenger" attribute if it exists.

    useStorefront(async (storefront) => {
        const flashMessengerApi = storefront.getApiSync('flashMessengerApi');

        const flashMessageId = flashMessengerApi.addFlashMessage({
            content: 'example message'
        }, 'my-flash-messenger');

        flashMessengerApi.removeFlashMessage(flashMessageId, 'my-flash-messenger');
    });
    <flash-messenger name="my-flash-messenger"></flash-messenger>

Example

Making a Flash Messages API call to add and then remove a flash message with a given id from a global Flash Messenger webcomponent.

    useStorefront(async (storefront) => {
        const flashMessengerApi = storefront.getApiSync('FlashMessengerApi');

        const flashMessageId = flashMessengerApi.addFlashMessage({
            content: 'example message'
        });

        flashMessengerApi.removeFlashMessage(flashMessageId);
    });

Flash Messenger API methods reference

Webcomponents reference