New product features | The latest in technology | The weekly debugging nightmares & more!
July 24, 2023
Take my knowledge and shove it up your brain...
When dealing with data mutations like updating users' data, it would be cool if the user gets notified that his changes were successful.
react-toastify team has done a great job allowing us to create beautiful notifications with only 3 lines of code.
To get started simply run npm i react-toastify
Toast.tsx
1import "react-toastify/dist/ReactToastify.css";
2import { ToastContainer, toast } from "react-toastify";
3export default function Toast() {
4 const notify = () => toast("Your address has been updated");
5 return (
6 <div>
7 <ToastContainer autoClose={3000} />
8 <button onClick={()=>{notify()}}>Notify Me!</button>
9 </div>
10 )
11}
The above code will simply create a button when clicked will trigger a browser notification.
This is just a simple example, in a real scenario, you'd call the function notify
after a certain action is taken like updating data or smth...
More details can be found on npm