How to create a Snackbar in react native using material design ?
Last Updated :
28 Mar, 2022
React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UI's for both platforms.
Prerequisites:
- Basic knowledge of ReactJS.
- HTML, CSS and JavaScript with ES6 syntax.
- Node.js should be installed in your system (install).
- Jdk and android studio for testing your app on emulator (install).
Approach: In this article, we will see how to create a snackbar in react native. To create a snackbar, we will use material design library i.e. react-native-paper. Snackbars are messages or feedback about an operation except they provide action to interact with. Snackbar will be displayed at the bottom of the screen and can be swiped off in order to dismiss them.
In our project , we will simply display a button and on click of button ,snackbar will appear at the bottom of the screen. we will the implementation step by step.
Below is the step by step implementation:
Step 1: Create a project in react-native using the following command:
npx react-native init DemoProject
Step 2: Install react-native paper using the following command:
npm install react-native-paper
Step 3: Create a components folder inside your project. Inside the components folder create a file Snackbar.js
Project Structure: It will look like this.

Implementation: Write down the code in respective files.
In Snackbar.js, we have imported Snackbar items directly from the react-native-paper library. It uses the following props :
- visible: It can be true or false to show or hide the Snackbar
- action: Label and press callback for the action button. It should contain the following properties:
- label - Label of the action button
- onPress - Callback that is called when action button is pressed.
- onDismiss: It is a Callback function called when Snackbar is dismissed. The visible prop needs to be updated when this is called.
Filename: Snackbar.js
JavaScript
import React, { useState } from "react";
import { Text, View, StyleSheet, Dimensions } from 'react-native';
import { Snackbar, Button } from "react-native-paper";
const screenHeight = Dimensions.get('window').height;
const SnackbarComponent = () => {
const [snackVisible, setSnackVisible] = useState(false);
return (
<View style={styles.container}>
<View style={styles.btn}>
<Button mode="contained"
onPress={() => setSnackVisible(!snackVisible)}>
Press
</Button>
</View>
<Snackbar
visible={snackVisible}
onDismiss={() => setSnackVisible(false)}
action={{ label: 'Proceed' }}>
Welcome to GeeksForGeeks
</Snackbar>
</View>
)
}
export default SnackbarComponent;
const styles = StyleSheet.create({
container: {
flexDirection: "column-reverse",
justifyContent: "flex-end",
height: screenHeight,
},
btn: {
marginVertical: 50,
alignItems: "center"
}
})
Now, import this file to your App.js
Filename: App.js
JavaScript
import React from 'react';
import type { Node } from 'react';
import { View } from 'react-native';
import SnackbarComponent from './components/Snackbar';
const App: () => Node = () => {
return (
<View>
<SnackbarComponent />
</View>
);
};
export default App;
Step to run the application: Run the application using the following command :
npx react-native run-android
Output:

Similar Reads
How to add a Menu in react-native using Material Design ? In this article, we will see how to create a menu in react-native. To make a menu, we will use the material design library, i.e., react-native-paper. The menu contains a list of options that appear temporarily. In our project, we will create a button, and the menu will appear on the click of that bu
9 min read
How to create a Toggle switch in react-native using Material Design library ? React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
2 min read
How to create Chip in react-native using react-native-paper ? React native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
2 min read
How to create Material Bottom Tab Navigator in React Native ? To create a Bottom Tab Navigator using Material, we need to use the createMaterialBottomTabNavigator function available in the react-navigation library. It is designed with the material theme tab bar on the bottom of the screen. It provides you with pleasing UI features and allows you to switch betw
3 min read
How to create a Surface in react-native ? React native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
3 min read