How to use SnackBar Component in ReactJS ? Last Updated : 26 Jul, 2024 Comments Improve Suggest changes Like Article Like Report ReactJS provides developers with a wide range of components to create interactive and dynamic web applications. One such component is the SnackBar, which is commonly used to display temporary messages or notifications to users. Creating a SnackBar component allows for the presentation of these messages. Let's explore how to implement a SnackBar component in a React application.PrerequisitesBasic knowledge of React and JavaScriptNode.js installed on your machineSteps to create the application:Step 1: Create a React application using the following command.npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command.cd foldernameStep 3: After creating the ReactJS application, Install the material-ui modules using the following command.npm install @material-ui/corenpm install @material-ui/iconsProject Structure:Project StructureExample: Now write down the following code in the App.js file. JavaScript import React from "react"; import IconButton from "@material-ui/core/IconButton"; import Snackbar from "@material-ui/core/Snackbar"; import CloseIcon from "@material-ui/icons/Close"; import Button from "@material-ui/core/Button"; export default function App() { const [open, setOpen] = React.useState(false); const handleToClose = (event, reason) => { if ("clickaway" == reason) return; setOpen(false); }; const handleClickEvent = () => { setOpen(true); }; return ( <div style={{}}> <h4> How to use SnackBar Component in ReactJS? </h4> <Button onClick={handleClickEvent}> Open Snackbar </Button> <Snackbar anchorOrigin={{ horizontal: "left", vertical: "bottom", }} open={open} autoHideDuration={5000} message="Sample Warning" onClose={handleToClose} action={ <React.Fragment> <IconButton size="small" aria-label="close" color="inherit" onClick={handleToClose} > <CloseIcon fontSize="small" /> </IconButton> </React.Fragment> } /> </div> ); } Step to Run Application: Run the application using the following command from the root directory of the project.npm startOutput: Now open your browser and go to http://localhost:3000/, you will see the following output. Comment More infoAdvertise with us Next Article How to use SnackBar Component in ReactJS ? gouravhammad Follow Improve Article Tags : JavaScript Web Technologies ReactJS Web technologies Material-UI React-Questions +2 More Similar Reads How to use Badge Component in ReactJS? Badge generates a small badge to the top-right of its children component. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Badge Component in ReactJS using the following approach. Prerequisites:NodeJS or NPMReact JSMaterial UISteps to Create 2 min read How To Use Modal Component In ReactJS? Modals are a popular UI component used to display content in a pop-up window like alerts, forms, or additional information. In ReactJS, there are multiple ways to implement a modal. In this article, we will discuss two common approaches: using reusable functional components and using the Material-UI 4 min read How to use Paper Component in ReactJS ? In Material Design, the physical properties of paper are translated to the screen. Material UI for React has this component available for us and it is very easy to integrate. We can use the Paper Component in ReactJS using the following approach. Prerequisites:React JSMaterial UIApproachTo use Paper 2 min read How to use Popper Component in ReactJS ? A Popper is used to show the part of the content on top of another. It's an alternative feature for react-popper. Material UI for React has this component available for us, and it is simple and very easy to integrate. For perfect positioning, it uses 3rd party library which is Popper.js.Prerequisite 3 min read How to use Icon Component in React JS? Every application requires icons for UI purposes, and integrating them with Material UI for React is seamless. Utilize the Icon Component in ReactJS effortlessly by following this straightforward approach. Prerequisites:NodeJS or NPMReact JSMaterial UISteps to create React Application And Installing 2 min read How to create Tabs in ReactJS ? Tabs make it easy to explore and switch between different views. Material UI for React has this component available for us and it is very easy to integrate. We can use Tabs Component in ReactJS using the following approach.Prerequisites:NPM & Node.jsReact JSMaterial UIwe have these approaches to 4 min read ReactJS Onsen UI Toolbar Component ReactJS Onsen-UI is a popular front-end library with a set of React components that are designed to developing HTML5 hybrid and mobile web apps in a beautiful and efficient way. Toolbar components allow the users to show them a toolbar that can be used with navigation. We can use the following appro 2 min read How to use BottomNavigation Component in ReactJS? The Bottom navigation bars allow movement between primary destinations in an app. Material UI for React has this component available for us and it is very easy to integrate. We can use BottomNavigation Component in ReactJS using the following approach.In this article we will learn to use BottomNavig 2 min read ReactJS Onsen UI Toast Component ReactJS Onsen-UI is a popular front-end library with a set of React components that are designed to developing HTML5 hybrid and mobile web apps in a beautiful and efficient way. Toast Component allows the user to display dismissible information or simple actions at the bottom of the page. We can use 2 min read ReactJS Reactstrap Toast Component Reactstrap is a popular front-end library that is easy to use React Bootstrap 4 components. This library contains the stateless React components for Bootstrap 4. The Toast Component allows the user to display dismissible information or simple actions at the bottom of the page. We can use the followi 3 min read Like