Toast
When an asynchronous operation is happening or when an error is thrown, it's usually a good idea to keep the user informed about it. Toasts are made for that.
Additionally, Toasts can have some actions associated to the action they are about. For example, you could provide a way to cancel an asynchronous operation, undo an action, or copy the stack trace of an error.

API Reference

showToast

Creates and shows a Toast with the given options.

Signature

1
async function showToast(options: Toast.Options): Promise<Toast>;
Copied!

Example

1
import { showToast, Toast } from "@raycast/api";
2
3
export default async () => {
4
const success = false;
5
6
if (success) {
7
await showToast({ title: "Dinner is ready", message: "Pizza margherita" });
8
} else {
9
await showToast({
10
style: Toast.Style.Failure,
11
title: "Dinner isn't ready",
12
message: "Pizza dropped on the floor",
13
});
14
}
15
};
Copied!
When showing an animated Toast, you can later on update it:
1
import { showToast, Toast } from "@raycast/api";
2
import { setTimeout } from "timers/promises";
3
4
export default async () => {
5
const toast = await showToast({
6
style: Toast.Style.Animated,
7
title: "Uploading image",
8
});
9
10
try {
11
// upload the image
12
await setTimeout(1000);
13
14
toast.style = Toast.Style.Success;
15
toast.title = "Uploaded image";
16
} catch (err) {
17
toast.style = Toast.Style.Failure;
18
toast.title = "Failed to upload image";
19
toast.message = err.message;
20
}
21
};
Copied!

Parameters

Name
Type
Required
Description
options
Yes
The options used to create the Toast.

Return

A Promise that resolves with the shown Toast. The Toast can be used to change or hide it.

Types

Toast

A Toast with a certain style, title, and message.
Use showToast to create and show a Toast.

Properties

Property
Description
Type
message*
An additional message for the Toast. Useful to show more information, e.g. an identifier of a newly created asset.
string
primaryAction*
The primary Action the user can take when hovering on the Toast.
secondaryAction*
The secondary Action the user can take when hovering on the Toast.
style*
The style of a Toast.
title*
The title of a Toast. Displayed on the top.
string

Methods

Name
Type
Description
hide
() => Promise<void>
Hides the Toast.
show
() => Promise<void>
Shows the Toast.

Toast.Options

The options to create a Toast.

Example

1
import { showToast, Toast } from "@raycast/api";
2
3
export default async () => {
4
const options: Toast.Options = {
5
style: Toast.Style.Success,
6
title: "Finished cooking",
7
message: "Delicious pasta for lunch",
8
primaryAction: {
9
title: "Do something",
10
onAction: (toast) => {
11
console.log("The toast action has been triggered");
12
toast.hide();
13
},
14
},
15
};
16
await showToast(options);
17
};
Copied!

Properties

Property
Description
Type
title*
The title of a Toast. Displayed on the top.
string
message
An additional message for the Toast. Useful to show more information, e.g. an identifier of a newly created asset.
string
primaryAction
The primary Action the user can take when hovering on the Toast.
secondaryAction
The secondary Action the user can take when hovering on the Toast.
style
The style of a Toast.

Toast.Style

Defines the visual style of the Toast.
Use Toast.Style.Success for confirmations and Toast.Style.Failure for displaying errors. Use Toast.Style.Animated when your Toast should be shown until a process is completed. You can hide it later by using Toast.hide or update the properties of an existing Toast.

Enumeration members

Name
Value
Animated
Success
Failure

Toast.ActionOptions

The options to create a Toast Action.

Properties

Property
Description
Type
title*
The title of the action.
string
onAction*
A callback called when the action is triggered.
(toast: Toast) => void
shortcut
The keyboard shortcut for the action.