Monday, October 6, 2025
HomeLanguagesReactJS UI Ant Design Notification Component

ReactJS UI Ant Design Notification Component

Ant Design Library has this component pre-built, and it is very easy to integrate as well. Notification Component is used to display a notification message globally. We can use the following approach in ReactJS to use the Ant Design Notification Component.

Notification Config Props:

  • bottom: When the placement is bottomRight or bottomLeft, it is used to denote the distance from the bottom of the viewport.
  • btn: It is used for the customized close button.
  • className: It is used for the customized CSS class.
  • closeIcon: It is used for the custom close icon.
  • description: It is used to denote the content of the notification box.
  • duration: It is used to set the time before Notification is closed. Unit is seconds.
  • getContainer: It is used to return the mount node for the notification.
  • icon: It is used for the customized icon.
  • key: It is used for the unique identity of the Notification.
  • message: It is used to denote the title of the notification box.
  • placement: It is used to position the Notification. Values can be topLeft, topRight, bottomLeft, and bottomRight.
  • style: It is used for the customized inline style.
  • top: When placement is topRight or topLeft, it is used to denote the distance from the top of the viewport.
  • onClick: It is a callback function that is triggered when the notification is clicked.
  • onClose: It is a callback function that is triggered when the notification is closed.

Notification Default Config Props:

  • bottom: When the placement is bottomRight or bottomLeft, it is used to denote the distance from the bottom of the viewport.
  • closeIcon: It is used for the custom close icon.
  • duration: It is used to set the time before Notification is closed. Unit is seconds.
  • getContainer: It is used to return the mount node for the notification.
  • placement: It is used to position the Notification. Values can be topLeft, topRight, bottomLeft, and bottomRight.
  • rtl: It is used to indicate whether to enable RTL mode or not.
  • top: When placement is topRight or topLeft, it is used to denote the distance from the top of the viewport.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:

    npx create-react-app foldername
  • Step 2: After creating your project folder i.e. foldername, move to it using the following command:

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

    npm install antd

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React from 'react'
import "antd/dist/antd.css";
import { Button, notification } from 'antd';
  
export default function App() {
  return (
    <div style={{
      display: 'block', width: 700, padding: 30
    }}>
      <h4>ReactJS Ant-Design Notification Component</h4>
      <Button type="primary" onClick={() => {
        notification.open({
          message: 'Sample-Notification-Title',
          description:
            'Sample Notification Description',
          onClick: () => {
            console.log('Notification Clicked!');
          },
        });
      }}>
        Click to see Notification Box
      </Button>
    </div>
  );
}


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

npm start

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

Reference: https://ant.design/components/notification/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6779 POSTS0 COMMENTS