parseAndAddFlashMessages(flashMessages: TFlashMessenger, containerName?: string): void¶
The parseAndAddFlashMessages
method parses messages taken from the server and then adds them to the page.
Input parameters¶
flashMessages¶
flashMessages
is a mandatory parameter of the TFlashMessenger type.
containerName (optional)¶
string
is a mandatory parameter that tell the api which flash-messenger should it refer to. If not specified the messages will be added to the global flash messenger.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- FlashMessengerApi.addFlashMessages - when displaying flash messages
Example¶
Making a Flash Messages API call to add a flash message to a Flash Messenger webcomponent with the name="my-flash-messenger"
attribute if it exists.
useStorefront(async (storefront) => {
const flashMessengerApi = storefront.getApiSync('flashMessengerApi');
const flashMessages: TFlashMessenger = {
error: ["error1", "error2"],
info: ["info1", "info2"],
success: ["success1", "success2"],
warning: ["warning1", "warning2"]
}
flashMessengerApi.parseAndAddFlashMessages(flashMessages, 'my-flash-messenger');
});
Example¶
Making a Flash Messages API call to parse flash messages to a global Flash Messenger webcomponent.
useStorefront(async (storefront) => {
const flashMessengerApi = storefront.getApiSync('FlashMessengerApi');
const flashMessages = {
error: ["error1", "error2"],
info: ["info1", "info2"],
success: ["success1", "success2"],
warning: ["warning1", "warning2"]
}
flashMessengerApi.parseAndAddFlashMessages(flashMessages);
});