How to add toast notifications in React
In this post we will see how to add toast notification to our react app
Installing required library
Run below command to install react-toastify
. React-toastify allows you to add notifications to your app with ease.
npm install --save react-toastify
or if you are using yarn
yarn add react-toastify
usage
paste the below code
import React from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
function App(){
const notify = () => toast("Wow so easy !");
return (
<div>
<button onClick={notify}>Notify !</button>
<ToastContainer />
</div>
);
}
when you run your app you will something like below
<img src="https://static.onecompiler.com/images/posts/3w3q4mj52/toasr.png" />