notification.addToast

API reference for the notification.addToast method.
This version of the API is a preview. Preview APIs are unstable and may change without warning. You can't release public apps using this API until it's stable.

A method that shows a toast notification to the user.

Usage

import { notification } from '@canva/platform';
import type { ToastRequest } from '@canva/platform';
const showToast = () => {
const request: ToastRequest = {
messageText: "Hello world!",
};
notification.addToast(request);
};
<Button onClick={() => showToast()}>Show Toast</Button>
TSX

Parameters

requestToastRequest
Required

Options for configuring a toast notification.

messageTextstring
Required

Text to show within the toast notification.

timeoutMsnumber | string
Optional

The duration that the notification will be visible.

If set to "infinite", the notification will be displayed until manually dismissed by the user.

If set to a number, the notification will automatically disappear after that duration (in milliseconds).

Default value: 5000

Returns

The result when a toast notification is successfully added. This is a Promise that resolves with the following object:

statusstring

The status of the request.

This must be "completed".