Skip to content

Toast

toast is an imperative API for showing transient notifications. You call it from anywhere in your app, and the Toaster component — mounted once at the root — renders the result.

Choose a type to pick which function fires — toast for neutral messages, toast.success / toast.danger for outcomes, toast.info for notices, and toast.loading / toast.promise for in-progress work. title is the bold heading and description the detail line (loading and promise toasts show only a title). Through options you can set a duration, allow or block dismissal with dismissible, and attach an action button; info toasts additionally take a secondaryAction, a ctaPosition, and a severity border. Try them in the playground below.

toast({
title: 'Toast title',
description: 'Toast description',
options: {
/**
* If duration is not provided,
* the toast will be closed after 10 seconds by default.
*/
duration: 5000,
dismissible: true,
action: {
label: 'Undo',
onClick: () => {
console.log('Undo')
}
}
}
})

Installation

import { Toaster, toast } from "@harnessio/ui/components";
// Mount the Toaster once, at the root of your app
<Toaster />;
// Then call toast from anywhere
toast({
title: "Saved",
description: "Your changes have been saved.",
});