Saturday, October 25, 2025
HomeLanguagesJavascriptHow to create toast in React Native ?

How to create toast in React Native ?

React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows, and UWP by enabling developers to use the React framework along with native platform capabilities.

In this article, we will be learning how to create toast in React Native.

Creating React Native App:

Step 1: We’ll be using expo to create the react native app. Install expo-cli using the below command in the terminal.

npm install -g expo-cli

Step 2: Create a react native project using expo.

expo init "gfg"

Step 3:Now go to the created project using the below command.

cd "gfg"

Project Structure: It will look like the following.

Adding the Toast: We can easily add toast in our react native app. For this, we are going to use the ToastAndroid API of react-native. 

Example: Add the below code in the App.js file.

Javascript




import React from "react";
import { ToastAndroid,Button, View, Text } from "react-native";
  
const GfGApp = () => {
  
  const GfGToast = () => {
    ToastAndroid.showWithGravity(
      "This is the demo text!!!!!!! ",
      ToastAndroid.SHORT,
      ToastAndroid.BOTTOM
    );
  };
    
  return (
    <View style={{ marginTop: 200 }}>
      <Text style={{fontSize:18}}>
          neveropen React Native Toast
      </Text>
      <Button
        title="Toggle Toast "
        onPress={() => GfGToast()}
      />
    </View>
  );
};
  
  
  
export default GfGApp;


Here first we are creating our toast using the ToastAndroid.showWithGravity function. Then we are toggling the toast every time the user presses the button.

Step to run the application: Now run the application using the below command in the terminal.

npm run web

Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS