Open In App

React MUI AlertTitle API

Last Updated : 26 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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 AlterTitle API. The Alert component allows the user to show important tips or messages on the page.

Import AlterTitle API:

import Alert from '@mui/material/Alert';
import AlertTitle from '@mui/material/AlertTitle';

Props list:

  • children: It is used to denote the content of the divider.
  • classes: It is to override or extend the styles applied to the component.
  • sx: It is used to add custom CSS styles to the divider.

CSS Rules:

  •  root (MuiDivider-root): It is the style applied to the root element.

Approach: Let us create a React project and install React MUI module. Then we will create a UI that will showcase React MUI AlertTitle 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 AlertTitle. 

App.js




import React from 'react';
import Alert from '@mui/material/Alert';
import AlertTitle from '@mui/material/AlertTitle';
  
export default function App() {
  
    return (
        <div className="App" style=
            {{ margin: 100 }}>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
            <h3>
                <u>React MUI AlertTitle API</u>
            </h3>
            <Alert severity="success">
                <AlertTitle>
                    Title of the alert
                </AlertTitle>
                <strong> This is an success
                    alert with a title.
                </strong>
            </Alert>
        </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 AlertTitle. 

App.js




import React from 'react';
import Alert from '@mui/material/Alert';
import AlertTitle from '@mui/material/AlertTitle';
  
export default function App() {
  
    return (
        <div className="App" style={{ margin: 100 }}>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
            <h3>
                <u>React MUI AlertTitle API</u>
            </h3>
            <Alert severity="success">
                <AlertTitle>Title 1</AlertTitle>
                <strong> This is an success alert
                    with a title.
                </strong>
            </Alert><br />
            <Alert severity="error">
                <AlertTitle>Title 2</AlertTitle>
                <strong> This is an error alert
                    with a title.
                </strong>
            </Alert><br />
            <Alert severity="warning">
                <AlertTitle>Title 3</AlertTitle>
                <strong> This is an warning alert
                    with a title.
                </strong>
            </Alert><br />
            <Alert severity="info">
                <AlertTitle>Title 4</AlertTitle>
                <strong> This is an info alert
                    with a title.
                </strong>
            </Alert>
        </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/alert-title/



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads