Alert
When the user takes an important action (for example when irreversibly deleting something), you can ask for confirmation by using confirmAlert.

API Reference

confirmAlert

Creates and shows a confirmation Alert with the given options.

Signature

1
async function confirmAlert(options: Alert.Options): Promise<boolean>;
Copied!

Example

1
import { confirmAlert } from "@raycast/api";
2
3
export default async () => {
4
if (await confirmAlert({ title: "Are you sure?" })) {
5
// do something
6
}
7
};
Copied!

Parameters

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

Return

A Promise that resolves to a boolean when the user triggers one of the actions. It will be true for the primary Action, false for the dismiss Action.

Types

Alert.Options

The options to create an Alert.

Example

1
import { Alert } from "@raycast/api";
2
3
export default async () => {
4
const options: Alert.Options = {
5
title: "Finished cooking",
6
message: "Delicious pasta for lunch",
7
primaryAction: {
8
title: "Do something",
9
onAction: () => {
10
// while you can register a handler for an action, it's more elegant
11
// to use the `if (await confirmAlert(...)) { ... }` pattern
12
console.log("The alert action has been triggered");
13
},
14
},
15
};
16
await confirmAlert(options);
17
};
Copied!

Properties

Property
Description
Type
title*
The title of an alert. Displayed below the icon.
string
dismissAction
The Action to dismiss the alert. There usually shouldn't be any side effects when the user takes this action.
icon
The icon of an alert to illustrate the action. Displayed on the top.
message
An additional message for an Alert. Useful to show more information, e.g. a confirmation message for a destructive action.
string
primaryAction
The primary Action the user can take.

Alert.ActionOptions

The options to create an Alert Action.

Properties

Property
Description
Type
title*
The title of the action.
string
style
The style of the action.
onAction
A callback called when the action is triggered.
() => void

Alert.ActionStyle

Defines the visual style of an Action of the Alert.
Use Alert.ActionStyle.Default for confirmations of a positive action. Use Alert.ActionStyle.Destructive for confirmations of a destructive action (eg. deleting a file).

Enumeration members

Name
Value
Default
Destructive
Cancel