Toaster and Toast Messages
A component and utility for displaying brief messages to users, typically used for notifications or alerts. Toast messages appear momentarily on top of the application UI.
You can display multiple toast messages at once, and they will be stacked neatly.
In this guide, you'll learn how to use the Toaster component.
Usage#
First, import the toast utility and Toaster component from @medusajs/ui:
Then, add the Toaster component somewhere in your tree hierarchy. For example, in your main application layout:
Finally, use the toast utility in your components to display a toast message:
API Reference#
Toast Utility Functions#
The toast utility has the following functions to display different variants of toast messages:
info: Display a toast message with an informational style.error: Display a toast message with an error style.success: Display a toast message with a success style.warning: Display a toast message with a warning style.loading: Display a toast message with a loading style.
Each of these functions accept two parameters:
- A string indicating the title of the toast.
 - An object of Toast component props.
 
Toast Props#
This component is based on the Sonner toast library.
| Prop | Type | Default | 
|---|---|---|
id | string| number | - | 
description | ReactNode | - | 
action | object | - | 
Toaster Props#
This component is based on the Toaster component of the Sonner library.
| Prop | Type | Default | 
|---|---|---|
position | Position | "bottom-right" | 
gap | number | 12 | 
offset | string| number | 24 | 
duration | number | 4000 | 
Examples#
Toast Variants#
Toaster component in your application's tree.Dismissable Toast#
Toaster component in your application's tree.Toast with Action#
Toaster component in your application's tree.