![]() |
VOOZH | about |
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.
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: Install the material-ui, emotion/react, mui/styled-engine, modules using the following command.
npm install @mui/material
npm install @emotion/react
npm install @mui/styled-engine
Project Structure:
package.json:
"dependencies": {
"@mui/material": "^5.14.18",
"@emotion/react": "^11.11.1",
"@mui/styled-engine": "^5.14.18",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example 1: In this example, we will create a simple Popper component that gets displayed at the click of a button. Please update your App.js file like below:
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
Example 2: In this example, we will create 2 Popper components that get displayed in different directions, one at the top and the other at the bottom in orientation.
Steps to run the application:
npm startOutput: