Ant Design Library has this component pre-built, and it is very easy to integrate as well. In response to user operations, the Message Component is used for displaying global messages as feedback. We can use the following approach in ReactJS to use the Ant Design Message Component.
Message Props:
content: It is used to denote the content of the message.
duration: It is used to denote the Time in seconds before auto-dismiss, don't dismiss if set to 0.
onClose: It is a callback function that is triggered when the message is closed.
Message Config Props:
className: It is used for the customized CSS class.
content: It is used to denote the content of the message.
duration: It is used to denote the Time in seconds before auto-dismiss, don't dismiss if set to 0.
icon: It is used for the customized icon.
key: It is used for the unique identification of the Message.
style: It is used for the customized inline style.
onClick: It is a callback function that is triggered when the message is clicked.
onClose: It is a callback function that is triggered when the message is closed.
Message Config Default Props:
duration: It is used to denote the Time in seconds before auto-dismiss.
getContainer: It is used to return the mount node for Message.
maxCount: It is used to denote the Max message show.
prefixCls: It is used for the prefix className of message node.
rtl: It is used to indicate whether to enable RTL mode or not.
top: It is used to denote the distance from the top.
Global static method:
message.config(options): This method is used for the global configuration of messages. It takes the options object as a parameter whose props are explained above (Refer to Message Config Default Props).
message.destroy(): This method is used to remove a message. This method does not take any parameters.
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 therequiredmodule using the following command:
npm install antd
Project Structure: It will look like the following.