# Toast Display brief messages to users. ```tsx import { Toast, createToaster } from '@skeletonlabs/skeleton-react'; export default function Default() { const toaster = createToaster({}); return ( <> {(toast) => ( {toast.title} {toast.description} )} ); } ``` ## Usage This component acts as a Singleton - meaning you only implement a single instance (typically at the root scope of your app) and then reused it over and over. To do this, implement the `` at the root scope of your app, and use a shared `createToaster()` instance to trigger messages to that group from anywhere in your application. ## Type ```tsx import { Toast, createToaster } from '@skeletonlabs/skeleton-react'; export default function Type() { const toaster = createToaster({}); return ( <>
{(toast) => ( {toast.title} {toast.description} )} ); } ``` Types can be specified in one of two ways: * Via a trigger method: `toaster.{info|success|warning|error}()` * Via the object key: `type: {info|success|warning|error}` ## Action Include an optional action button. ```tsx import { Toast, createToaster } from '@skeletonlabs/skeleton-react'; export default function Action() { const toaster = createToaster({}); return ( <> {(toast) => ( {toast.title} {toast.description} {toast.action && {toast.action.label}} )} ); } ``` ## Closable By passing `closable: false` you can disable the close button. ```tsx import { Toast, createToaster } from '@skeletonlabs/skeleton-react'; export default function Closable() { const toaster = createToaster({}); return ( <> {(toast) => ( {toast.title} {toast.description} {toast.closable && } )} ); } ``` ## Placement ```tsx import { Toast, createToaster } from '@skeletonlabs/skeleton-react'; export default function Placement() { const toaster = createToaster({ placement: 'bottom-end', }); return ( <> {(toast) => ( {toast.title} {toast.description} )} ); } ``` ## Meta Use the `meta` key to provide arbitrary data. Then use this to modify your Toast template. ```tsx import { Toast, createToaster } from '@skeletonlabs/skeleton-react'; import { SkullIcon } from 'lucide-react'; export default function Meta() { const toaster = createToaster({}); return ( <> {(toast) => ( {toast.meta!.icon} {toast.title} {toast.description} )} ); } ``` ## Promise Use promises for asynchronous triggers. ```tsx import { Toast, createToaster } from '@skeletonlabs/skeleton-react'; export default function Promise_() { const toaster = createToaster({}); function generatePositiveNumber() { return new Promise((resolve, reject) => { setTimeout(() => { const number = Math.random() - 0.5; if (number > 0) { resolve(number); } else { reject(number); } }, 2000); }); } return ( <> {(toast) => ( {toast.title} {toast.description} )} ); } ``` ## API Reference | Property | Default | Type | | -------- | ------- | ----------------------------------------------------------------------------------------------- | | toast | - | Omit\, "id" \| "parent"> | | element | - | ((attributes: HTMLAttributes\<"div">) => Element) \| undefined — Render the element yourself | | children | - | (toast: ToastApi\) => ReactNode | | toaster | - | ToastStore\ | | children | - | ((toast: ToastProps\) => Element \| null) \| undefined | | element | - | ((attributes: HTMLAttributes\<"div">) => Element) \| undefined — Render the element yourself | | element | - | ((attributes: HTMLAttributes\<"div">) => Element) \| undefined — Render the element yourself | | element | - | ((attributes: HTMLAttributes\<"div">) => Element) \| undefined — Render the element yourself | | element | - | ((attributes: HTMLAttributes\<"div">) => Element) \| undefined — Render the element yourself | | element | - | ((attributes: HTMLAttributes\<"button">) => Element) \| undefined — Render the element yourself | | element | - | ((attributes: HTMLAttributes\<"button">) => Element) \| undefined — Render the element yourself |