How to use mui paper with button in react js?
November 16, 2023Hi Friends 👋,
Welcome To aGuideHub!
To use mui paper with
button in React JS, you have to use the <Button>
component in the paper. it will use mui paper with button in React JS.
Today, I am going to show you, How to use mui paper with button in react js
Installation
Install the following packages to use mui Paper in react js.
npm
npm install @mui/material @emotion/react @emotion/styled
yarn
yarn add @mui/material @emotion/react @emotion/styled
Table of contents
- Install MUI and create a new React app.
- Import Material-UI Paper.
- Use mui paper with button Component.
Step 1: Install MUI and create a new React app.
First you have to install the React project. You should use create-react-app
command to create a new React project.
npx create-react-app my-app
cd my-app
npm start
Step 2: Import Material-UI Paper.
After installing MUI
, you have to import your React component. To do this, add the following line to the top of your component file.
import React from "react";
import Paper from "@mui/material/Paper";
import Button from "@mui/material/Button";
import Box from "@mui/material/Box";
Step 3: Use mui paper with button Component.
The Paper component is a container for displaying content on an elevated surface.
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
"& > :not(style)": {
width: 100,
height: 38
}
}}
>
<Paper elevation={2}>
<Button>Click me</Button>
</Paper>
</Box>
MUI material use mui paper with button example.
The below code is an example, you need to import Paper
Component. Then, you have to use the <Button>
component in the paper. Then it will use mui paper with button in react js.
App.js
import React from "react";
import Paper from "@mui/material/Paper";
import Button from "@mui/material/Button";
import Box from "@mui/material/Box";
const MyComponent = () => {
return (
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
"& > :not(style)": {
width: 100,
height: 38
}
}}
>
<Paper elevation={2}>
<Button>Click me</Button>
</Paper>
</Box>
);
};
export default MyComponent;
In the above code example, I have used the @mui/material
component and use mui paper with button in react js.
Here, we are provided code sandbox links for the above program use mui paper with button in react js. Then you can use whenever you want and do the changes as per your requirements.
All the best 👍