Skip to Content

Toast

A notification system built on Base UI’s Toast primitive. Toasts slide in from the bottom-right corner and auto-dismiss. The useToast hook triggers them from anywhere within the provider.

Import

import { Toast } from "chunks-ui";

Setup

Wrap your app (or the relevant subtree) with Toast.Provider and place Toast.Viewport where the toasts should render:

export default function RootLayout({ children }) { return ( <Toast.Provider> {children} <Toast.Viewport /> </Toast.Provider> ); }

Basic Usage

Use Toast.useToast() to get the add function and trigger notifications:

function SaveButton() { const { add } = Toast.useToast(); return ( <button onClick={() => add({ title: "Saved", description: "Your changes have been saved." })}> Save </button> ); }

Multiple Toasts

Multiple toasts stack in the viewport. Each call to add creates an independent toast:

With Action

Pass actionProps to render a labelled action button inside the toast:

const { add } = Toast.useToast(); add({ title: "Message deleted", description: "The message has been removed from your inbox.", actionProps: { children: "Undo", onClick: () => restoreMessage(), }, });

Compound Parts

PartDescription
Toast.ProviderContext provider. Must wrap any component that calls useToast.
Toast.ViewportFixed-position container that renders all active toasts.
Toast.RootIndividual toast wrapper with slide/fade enter/exit transitions.
Toast.TitleBold toast heading.
Toast.DescriptionSupporting text in text-muted-foreground.
Toast.CloseIcon button that dismisses the toast.
Toast.ActionOptional action button rendered inside the toast.
Toast.useToastHook that returns { add, toasts } for the nearest provider.

Toast.useToast — add Options

OptionTypeDescription
titlestringToast heading text
descriptionstringSupporting body text
actionProps{ children: ReactNode; onClick: () => void }Props for the action button
timeoutnumberAuto-dismiss delay in milliseconds (provider default applies if omitted)

Toast.Provider Props

PropTypeDefaultDescription
timeoutnumber5000Default auto-dismiss delay in ms
limitnumberMaximum number of toasts shown simultaneously

Toast.Viewport Props

PropTypeDefaultDescription
classNamestringAdditional CSS classes on the viewport container
Last updated on