Alert

Learn how to use the Alert API to show pop-up messages in React Native applications.

We'll cover the following...

The Alert API is used to show essential information and warning messages to users. It can also be used to interrupt a user and ask them for a final confirmation of their decision before proceeding. For example, the Alert API can be displayed to show a warning message if the user is about to delete a system-related file.

Usage

To implement and use the Alert API, we first have to import it from the react-native library.

Press + to interact
import { Alert } from 'react-native';

Once the Alert API has been imported, we can use it inside our application using the alert method of the Alert API.

Press + to interact
import React from "react";
import { SafeAreaView, Button, Alert } from "react-native";
const App = () => {
return (
<SafeAreaView>
<Button
title = 'Click me'
onPress={() => Alert.alert('Hello World')}
/>
</SafeAreaView>
);
};
export default App;

Customizing alerts

We ...