PrimeUI PRO for React is now available 🚀View Demos
styledMessages

Toast

Toast is a component that displays a message to the user.

preview

Usage#

import { Toast } from '@primereact/ui/toast';
import { Toaster, toast } from '@primereact/ui/toaster';
<Toaster.Root>
    <Toaster.Portal>
        <Toaster.Region>
            {({ toaster }) =>
                toaster?.toasts?.map((t) => (
                    <Toast.Root key={t.id} toast={t}>
                        <Toast.Content>
                            <Toast.Icon match="success">
                                <Check />
                            </Toast.Icon>
                            <Toast.Icon match="error">
                                <Times />
                            </Toast.Icon>
                            <Toast.Icon match="warn">
                                <ExclamationTriangle />
                            </Toast.Icon>
                            <Toast.Icon match="info">
                                <InfoCircle />
                            </Toast.Icon>
                            <Toast.Message>
                                <Toast.Title />
                                <Toast.Description />
                                <Toast.Action />
                            </Toast.Message>
                            <Toast.Close />
                        </Toast.Content>
                    </Toast.Root>
                ))
            }
        </Toaster.Region>
    </Toaster.Portal>
</Toaster.Root>

Trigger toasts from anywhere with toast(...) or one of the severity shortcuts (toast.success, toast.info, toast.warn, toast.error, toast.secondary, toast.contrast).

Examples#

Severity#

Six built-in severities: info, success, warn, error, secondary, contrast. Pass severity directly or use the shortcut method.

toast({ severity: 'success', title: 'Saved' });
toast.success({ title: 'Saved' });
severity-demo

Promise#

toast.promise ties a toast to a promise, show a loading state, then transition to success or error based on the outcome.

promise-demo

Update#

toast.update(id, options) merges new options into an existing toast, useful for turning a loading toast into a result.

update-demo

Sticky#

Pass duration: Infinity to keep a toast open until it is dismissed manually. To make every toast sticky by default, set the timeout prop on Toaster to Infinity instead of per toast.

sticky-demo

Custom#

Pass render to replace the default body with custom JSX. The root wrapper (positioning, animation, swipe) is preserved.

custom-demo

Position#

Use the position prop on <Toaster.Root> to control where toasts appear.

position-demo

Expanded Mode#

mode="expanded" always renders the stack expanded; the default stacks toasts collapsed and expands on hover.

expanded-mode-demo

Action#

Add an interactive button to the toast with the action field.

action-demo

toast function#

toast(options) queues a toast and returns its id.

const id = toast({ severity: 'success', title: 'Saved' });

Severity shortcuts#

Each severity has a shortcut that sets severity automatically:

toast.success({ title: 'Saved' });
toast.info({ title: 'Heads up' });
toast.warn({ title: 'Check this' });
toast.error({ title: 'Failed' });
toast.secondary({ title: '...' });
toast.contrast({ title: '...' });

Methods#

toast.dismiss(id); // dismiss specific toast
toast.dismiss(); // dismiss all
toast.update(id, options); // merge options into existing toast
toast.promise(p, { loading, success, error });

Toast options#

Any of these fields can be passed to toast(...) or its shortcuts.

FieldTypeDescription
severity'info' | 'success' | 'warn' | 'error' | 'secondary' | 'contrast'Visual severity. Defaults to info.
titleReactNodeMain heading.
descriptionReactNodeSecondary text.
iconReactNodeCustom icon, overrides the matched <Toast.Icon match="..." /> for this toast.
actionButtonPropsProps forwarded to <Toast.Action> (e.g. children, onClick).
renderReactElementReplaces the default body with custom JSX.
durationnumberAuto-dismiss delay in ms. Pass Infinity to keep open.
loadingbooleanMarks the toast as loading and disables auto-dismiss.
dismissiblebooleanIf false, hides the close button and disables swipe-to-dismiss.
groupstringScopes the toast to a specific <Toaster.Root group="..." />.
dataRecord<string, unknown>Arbitrary metadata, available on the toast object and in callbacks.
onDismiss(toast) => voidCalled when dismissed by user (close button, swipe, or dismiss(id)).
onTimeout(toast) => voidCalled when duration elapses.

Sub-Components#

See Toast Primitive API for the full sub-component API reference.

Hooks#

See Toast Headless API for the hook API reference.

Accessibility#

See Toast Primitive for WAI-ARIA compliance details and keyboard support.