Skip to content

FlashMessengerApi.removeFlashMessage

FlashMessengerApi.removeFlashMessage is an event on the Event Bus that occurs whenever a Flash Message is being removed from the Flash Messenger.

Event body

The FlashMessengerApi.removeFlashMessage body has a TRemoveFlashMessageEvent type which represents the flash message to remove. It is optional so it might not exist.

Example

In this example we listen to FlashMessengerApi.removeFlashMessage event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    storefront.eventBus.on('FlashMessengerApi.removeFlashMessage', ({ body }) => {
        console.log('Flash message has been removed with id:', body.id, 'from flash messenger of name:', body.containerName);
    });
});

Example

In this example we use a Message Storage API to retrieve an array of past FlashMessengerApi.removeFlashMessage events.

useStorefront((storefront) => {
    const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');

    const pastRemoveFlashMessageEvents = messageStorageApi.getChannelMessages('FlashMessengerApi.removeFlashMessage');

    if (pastRemoveFlashMessageEvents.length > 0) {
        pastRemoveFlashMessageEvents.forEach(({ body: eventBody }) => {
            console.log('perform action on every past event');
        });
    }
});

JS API reference