Open In App

React MUI Divider API

React MUI is a UI library providing predefined robust and customizable components for React for easier web development. The MUI design is based on top of Material Design by Google. 

In this article, we are going to discuss the React MUI Divider API. The Alert component allows the user to show important tips or messages on the page. The divider allows the user to separate UI components from each other by adding a new line.



Importing the Divider API:

// Import Statement
import Divider from '@mui/material/Divider';

 



Props list:

CSS Rules:

Approach: Let us create a React project and install React MUI module. Then we will create a UI that will showcase React MUI Divider API.

Creating React Project:

Step 1: To create a react app, you need to install react modules through npx command. “npx” is used instead of “npm” because you will be needing this command in your app’s lifecycle only once.

npx create-react-app project_name

Step 2: After creating your react project, move into the folder to perform different operations.

cd project_name

Step 3: After creating the ReactJS application, Install the required module using the following command:

npm install @mui/material @emotion/react @emotion/styled
npm install @mui/lab

Project Structure: After running the commands mentioned in the above steps, if you open the project in an editor you can see a similar project structure as shown below. The new component user makes or the code changes, we will be performing will be done in the source folder.

Project Structure

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Example 1: We are creating a UI that shows React MUI Divider. 




import React from 'react';
import Divider from '@mui/material/Divider';
  
const myComponentStyle = {
    height: 30,
    paddingTop: 10,
    backgroundColor: "green",
    color: "white",
    fontWeight: "bold",
    textAlign: "center"
}
  
export default function App() {
  
    return (
        <div className="App"
            style={{ textAlign: "center" }}>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks</h1>
            <h3><u>React MUI  Divider API</u></h3>
            <p style={myComponentStyle}>Section</p>
            <Divider>Divider 1</Divider>
            <p style={myComponentStyle}>Section</p>
            <Divider>Divider 2</Divider>
            <p style={myComponentStyle}>Section</p>
            <Divider>Divider 3</Divider>
            <p style={myComponentStyle}>Section</p>
        </div>
    );
}

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Example 2: We are creating a UI that shows React MUI Divider. 




import React from 'react';
import Divider from '@mui/material/Divider';
import Grid from '@mui/material/Grid';
  
export default function App() {
  
    return (
        <div className="App"
            style={{ textAlign: "center" }}>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3><u>React MUI  Divider API</u></h3>
            <p>GFG courses:</p>
            <Grid><b style={{ color: "green" }}>
                DSA Self Paced </b>
            </Grid>
            <Divider flexItem>Divider 1</Divider>
            <Grid><b style={{ color: "green" }}>
                Amazon SDE Preparation Test Series</b>
            </Grid>
            <Divider flexItem>Divider 2</Divider>
            <Grid><b style={{ color: "green" }}>
                Complete Interview Preparation</b>
            </Grid>
        </div>
    );
}

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

 

Reference: https://mui.com/material-ui/api/divider/


Article Tags :