Never heard of react-toastify before? Go check the demo
What is new in v11
I’m super excited about this release! The main focus was on customization, and my goal was to empower you (and myself) so you can fully personalize the look and feel for the notifications.
In short, react-toastify should be able to blend into any design system.
No need to import the css file anymore
The stylesheet is now injected automatically, so you no longer need to import it. The CSS file is still exported by the library.
import { ToastContainer, toast } from 'react-toastify'; function App(){ const notify = () => toast("Wow so easy !"); return ( <div> <button onclick="{notify}">Notify !</button> <toastcontainer></toastcontainer> </div> ); }
Easy customization!
One of the top requests has been how to customize notifications. To be fair, until this release, it was quite challenging because it required users to override numerous CSS classes.
I’ve simplified the DOM structure of the notification by removing extraneous div elements, nested elements, etc... It’s a significant breaking change, but it’s truly worth the effort. I can confidently say that the library can now seamlessly integrate into any design system.
Below, I’ve implemented a couple of different designs using only Tailwind. I didn’t override a single CSS class from react-toastify ?!
Head to stackblitz to check the code.
How does it work in practice? On the left side, we have the old DOM structure vs the new one on the right side.
- Toastify__toast-body and its child are now completely gone.
- The CloseButton now uses an absolute position.
Thanks to those changes, nothing will interfere with your content.
Toastify__toast has some sensible default values(e.g., border-radius, shadow, etc...) that can be customized using css or by updating the associated css variables:
width: var(--toastify-toast-width); min-height: var(--toastify-toast-min-height); padding: var(--toastify-toast-padding); border-radius: var(--toastify-toast-bd-radius); box-shadow: var(--toastify-toast-shadow); max-height: var(--toastify-toast-max-height); font-family: var(--toastify-font-family);
Custom progress bar
Allowing a custom progress bar wasn’t on my to-do list at all while working on this release. But seeing how easy it is to customize notifications now, I couldn’t resist ?.
The best part is that you don’t have to compromise on features like autoClose, pauseOnHover,pauseOnFocusLoss, or even a controlled progress bar—it just works seamlessly for you.
Here is a small gist.
function App() { const notify = () => { toast(CustomComponent, { autoClose: 8000, // removes the built-in progress bar customProgressBar: true }); }; return ( <div> <button onclick="{notify}">notify</button> <toastcontainer></toastcontainer> </div> ); } // isPaused is now available in your component // it tells you when to pause the animation: pauseOnHover, pauseOnFocusLoss etc... function CustomComponent({ isPaused, closeToast }: ToastContentProps) { return ( <div> <span>Hello</span> <mycustomprogressbar ispaused="{isPaused}" onanimationend="{()"> closeToast()} /> </mycustomprogressbar> </div> ); }
Head to stackblitz for a live example.
Accessibility and keyboard navigation
ToastContainer and toast accept an ariaLabel prop(finally...). This is quite helpful for screen readers and also for testing.
For example, in cypress you could do cy.findByRole("alert", {name: "the aria label you specified"}).
import { ToastContainer, toast } from 'react-toastify'; function App(){ const notify = () => toast("Wow so easy !"); return ( <div> <button onclick="{notify}">Notify !</button> <toastcontainer></toastcontainer> </div> ); }
If a notification is visible and the user presses alt t it will focus on the first notification allowing the user to use Tab to navigate through the different elements within the notification.
The hotKeys can be changed of course.
width: var(--toastify-toast-width); min-height: var(--toastify-toast-min-height); padding: var(--toastify-toast-padding); border-radius: var(--toastify-toast-bd-radius); box-shadow: var(--toastify-toast-shadow); max-height: var(--toastify-toast-max-height); font-family: var(--toastify-font-family);
Notification removal reason with onClose callback
Do you want to know whether the user closed the notification or if it closed automatically? Rest assured, this is now possible!
The signature of the onClose callback is now onClose(reason?: boolean | string) => void.
When the user closes the notification, the reason argument is equal to true. In the example below, I've named my argument
removedByUser to make the intent clear.
function App() { const notify = () => { toast(CustomComponent, { autoClose: 8000, // removes the built-in progress bar customProgressBar: true }); }; return ( <div> <button onclick="{notify}">notify</button> <toastcontainer></toastcontainer> </div> ); } // isPaused is now available in your component // it tells you when to pause the animation: pauseOnHover, pauseOnFocusLoss etc... function CustomComponent({ isPaused, closeToast }: ToastContentProps) { return ( <div> <span>Hello</span> <mycustomprogressbar ispaused="{isPaused}" onanimationend="{()"> closeToast()} /> </mycustomprogressbar> </div> ); }
If you are using a custom component for your notification, you might want more control over the reason, especially if it contains
multiple call to actions.
toast("hello", { ariaLabel: "something" })
? Breaking Changes
useToastContainer and useToast no longer exposed
Those hooks are unusable unless you deep dive in react-toastify source code to understand how to glue things together. This is not what I want for my users, it was a bad decision to expose them in the first place, I've learned a good lesson.
onClose and onOpen no longer receive children props
In hindsight, I should never have done this. The feature is practically not used. Below the new signature for each callback:
- onOpen: () => void
- onClose: (reason?: boolean | string) => void
Styling
- react-toastify/dist/ReactToastify.minimal.css has been removed.
- Scss is out of the picture now. The library uses good old css.
- bodyClassName and bodyStyle are no longer needed.
- progressBarStyle in order to reduce the api surface. They are now better way to customize everything without relying on inline style.
- injectStyle has been removed. This function is no longer needed.
- The css class Toastify__toast-body and its direct child have been removed.
? Bug Fixes
- add support for react19 #1177 #1185
- reexport CloseButtonProps #1165
- fix newestOnTop for real this time #1176
- no longer throw this ugly error: Cannot set properties of undefined (setting 'toggle') #1170
- onClose callback is no longer delayed until the exit animation completes #1179
?What's next?
I'm gradually rewriting part of the documentation. I've created a collection on stackblitz, this way you can find all the examples in one place. I'll keep adding more examples as I go.
The above is the detailed content of React-toastify v- finally easy to customize. For more information, please follow other related articles on the PHP Chinese website!

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment
