On September 25th, 2024, we released v2 of the Apps SDK. To learn what’s new and how to upgrade, see Migration FAQ and Migration guide.

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

requestToastRequestRequired

Options for configuring a toast notification.

messageTextstringRequired

Text to show within the toast notification.

timeoutMsnumber | stringOptional

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".