The useMessages hook provides a way to manage application messages (notifications, alerts, etc.) in a React application. It allows you to add, remove, and clear messages throughout your application.
Import
Usage
Return Value
Returns an object with:
messages: Message[] - Array of all current message objects
addMessage: (message: AddMessageInput) => void - Function to add a new message. Accepts either a content (a direct message) or an error (a ServerError, automatically resolved into a localized message via translations)
removeMessage: (messageId: string) => void - Function to remove a message by its ID
clearAll: () => void - Function to remove all messages
Message Object
Each message in the messages array has the following structure:
Message is described by the following structure:
| Property | Type | Description |
|---|
id | string | A unique identifier for the message (automatically generated) |
type | enum | The type of message info | success | warning | error |
content | string | The main text content of the message |
title | string | Optional title for the message |
Example
The example below shows two different messages, a success and an error
| Desktop | Mobile |
|---|
 |  |
To achieve the result in the example above :
Examples per Action
addMessage(message)
Adds a new message to the message stack.
Parameters
message: an AddMessageInput. Provide either content (a direct message) or error (a ServerError to auto-resolve a localized message). type is required; title is optional.
removeMessage(messageId)
Removes a specific message from the stack by its ID.
Parameters
messageId: id of the message to remove
Messages are not dismissed automatically. They stay in the stack until you
remove them with removeMessage(id) or clearAll(). The rendering layer is
responsible for any auto-dismiss behavior.
clearAll()
Removes all messages from the message stack.