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:
- FlashMessengerApi.removeFlashMessage - when removing a flash message
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.
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);
});