What is the Alert API in React Native?
Answer
The Alert API displays native platform alert dialogs — iOS alert sheets and Android dialog boxes. It provides simple yes/no confirmations and multi-button dialogs using the platform's native UI. Simple alert: import { Alert } from "react-native"; Alert.alert("Title", "Message body"); // OK button automatically. Confirm dialog: Alert.alert( "Delete Item", "Are you sure you want to delete this?", [ { text: "Cancel", style: "cancel", // styled as cancel action onPress: () => console.log("Cancelled"), }, { text: "Delete", style: "destructive", // red on iOS onPress: () => deleteItem(), }, ] );. Alert.prompt (iOS only): alert with a text input field — not available on Android: Alert.prompt( "Enter Name", "Please enter your name:", [ { text: "Cancel", style: "cancel" }, { text: "OK", onPress: name => console.log("Name:", name) } ], "plain-text", "Default Value" );. Button styles: "default" (normal), "cancel" (bold on iOS), "destructive" (red on iOS). Limitations: Alert is platform-native — appearance differs between iOS and Android; can't heavily customize the UI; for custom styled dialogs, use the Modal component or react-native-modal library. Blocking: Alert is non-blocking — the callback fires asynchronously. The JS thread continues after Alert.alert() is called.
Previous
What is the Dimensions API in React Native?
Next
What is the FlatList component and its key props?