React-Toastify

react-hot-toast is smaller alternative

yarn add react-toastify

Setup

import React from 'react';
import { ToastContainer, toast } from 'react-toastify';

import 'react-toastify/dist/ReactToastify.min.css';

function App() {
  const notify = () => toast("Wow so easy !");

  //Include Toast Container somewhere in root
  return <div>
     <button onClick={notify}>Notify !</button>
    	
      <ToastContainer />
   </div>;
}

toast.configure adds ToastContainer to App

Configurations

Can do at the toast.configure level or override it when calling toast

toast.configure/ToastContainer

  • Position: top-right, top-center, top-left, bottom-right, bottom-center, bottom-left

Toast component

Customize

If you configure in individual, then you lose access to the outer container and className becomes toastClassName

Controlled Progress Bar Example

Last updated