What is the Alert API in React Native?

Why Interviewers Ask This

This is a classic screening question for React Native roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

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.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.