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 objectsaddMessage: (message: AddMessageInput) => void- Function to add a new message. Accepts either acontent(a direct message) or anerror(aServerError, automatically resolved into a localized message via translations)removeMessage: (messageId: string) => void- Function to remove a message by its IDclearAll: () => void- Function to remove all messages
Message Object
Each message in themessages array has the following structure:
Example
The example below shows two different messages, asuccess and an error
To achieve the result in the example above :
Examples per Action
addMessage(message)
Adds a new message to the message stack.Parameters
message: anAddMessageInput. Provide eithercontent(a direct message) orerror(aServerErrorto auto-resolve a localized message).typeis required;titleis optional.
removeMessage(messageId)
Removes a specific message from the stack by its ID.Parameters
messageId:idof the message to remove

