In this article, we will learn how to create a modal popup in React application using Material UI.
Prerequisites of React
- Familiarity with the HTML, JavaScript.
- node.js installed
Create React Project
To create a React app, use the following command in the terminal.
Open the newly created project in Visual Studio Code, and install Material-UI; run the following command in your React project's root directory.
Now right-click on the src folder and create a new component named 'Modalpopup.js'. We will create a simple modal popup using material UI. Import the following component from Material UI in the Modalpopup.js file.
Now, add the following code in the Modalpopup.js file.
In the above code, we have two functions for open and close popups named handleopen and handleclose, On button click. We call the handleopen function, and the modal popup opens by clicking the button.
Now, import the modalpopup component in the src/App.js file.
Now, run the project using the 'npm start' command and check the result.
![Material UI in React Application]()
Now click on the open modal button.
![Material UI in React Application]()
Summary
This article provides a step-by-step guide on how to create a Modal popup in a React application using the Material UI library.