Skip to main content

React Toastify

Quick start

npm i react-toastify
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>
);
}

CommonOptions

Props | OptionsTypeDefaultDesc
position(top|bottom)-(left|center|right)top-right
autoCloseboolean | number5000Delay (ms) before close, manual close if false
closeButtonComponent | booleancustom or false to hide
transitionComponentBounceUse react-transition-group | Transition component
hideProgressbarbooleanfalse
pauseOnHoverbooleantrue
pauseOnFocusLossbooleantruePause when window loses focus
closeOnClickbooleanfalseDismiss toast if click inside
classNamestringcontainer class
styleobjectcontainer styles
toastClassNamestring
bodyClassNamestringtoast's body class
progressClassNamestring
progressStyleobject
draggableboolean | "mouse" | "touch"touch
draggablePercentnumber80drag to dismiss when toast's width below (number)
draggableDirection"x" | "y"
containerIdstring | numberUse in case app have multiples ToastContainer
rolestringalertdefine ARIA role

Toast Container

PropsTypeDefaultDesc
rtlbooleanfalseSupport content right to left
stackedbooleanfalseNewest on top
newestOnTopbooleanfalse
limitnumberlimits toast show in screen
theme"light" | "dark" | "colored"light

Toast Emitter

OptionTypeDesc
toastIdstring | numberCustom ID
typesuccess | info | warn | error
onOpen(props) => void
onClose(props) => void
onClick(props) => void
delaynumber
renderComponentavailable for toast.update
isLoadingbooleanavailable for toast.loading
dataobjectanything you want to put in toast but not affect toast
toast(message | Component, options);

toast.success(message | Component, options?);
toast.info(message | Component, options?);
toast.warn(message | Component, options?);
toast.error(message | Component, options?);

toast.dismiss(toastId?); // Remove all if not provide param
toast.dismiss({ id: "", containerId });

toast.isActive(toastId);

toast.update(toastId, { type, render }); // ?

toast.clearWaitingQueue(); // clear waiting queue when working with limit
toast.clearWaitingQueue({ containerId });

toast.done(toastId); // completes progressbar

// control timer
toast.play({ id });
toast.pause({ id });

cssTransition

References: Animate Document

const Effect = cssTransition({
// required
enter: 'effect_start',
exit: 'effect_end',
// optional: default
appendPosition: false,
collapse: true,
collapseDuration: 300
});
import "animate.css/animate.min.css";
import "react-toastify/dist/ReactToastify.css";
import { ToastContainer, toast, cssTransition } from "react-toastify";

const bounce = cssTransition({
enter: "animate__animated animate__bounceIn",
exit: "animate__animated animate__bounceOut"
});

export default function App() {
function animateCss() {
toast.dark("Hey 👋, see how easy!", {
// transition: bounce
});
}

return (
<>
<div className="App">
<div className="btn-group">
<button className="btn" onClick={animateCss} id="animate.css">
Example using animate.css
</button>
</div>
</div>
<ToastContainer transition={bounce} />
</>
);
}