Skip to content

Toaster

The place where toasts appear. Put one at the root of the app; then toast() can be called from anywhere.

import { Toaster, toast } from '@sypnia/ui/react'

On this page
  1. One Toaster, many toasts
  2. When to use it
  3. For everyone

One Toaster, many toasts

Code
import { Button, Toaster, toast } from '@sypnia/ui/react';

// Place one Toaster at the root of the app; call toast() from anywhere.
export default function Root() {
  return (
    <>
      <div className="sy-row">
        <Button onClick={() => toast('Saved')}>Save</Button>
        <Button onClick={() => toast('The export failed', { tone: 'fail', detail: 'The file was larger than 50 MB. Export fewer rows.' })}>Fail</Button>
        <Button onClick={() => toast('Row deleted', { action: { label: 'Undo', onClick: () => toast('Row restored') } })}>Delete a row</Button>
      </div>
      <Toaster />
    </>
  );
}

When to use it

Use it when

  • Once per app, beside the AppShell.
  • Results that leave by themselves: «Saved», «Row deleted» with Undo.

Do not use it when

  • Relying on it without placing one: with no Toaster on the page, toast() shows nothing.
  • Anything the person must read or decide: use an Alert or a Dialog.

For everyone

  • It is a region named «Notifications»; each toast is a polite status.
  • Toasts with an action stay longer, and each one can be dismissed.
  1. One Toaster, many toasts
  2. When to use it
  3. For everyone

    Search pages, sections and terms