The following code renders a toast:
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
export default function App() {
const notify = () =>
toast.success("Yabba dabba do", {
onClose: () => {
console.log("closing");
},
autoClose: 5000
});
return (
<div>
<button onClick={notify}>Notify !</button>
<ToastContainer />
</div>
);
}
However, in the console the statement "closing" outputs as soon as the toast renders and again 5 seconds later after the toast closes. How do I code it so that "closing" only outputs to the console after 5 seconds when the toast closes? Here's a Codesandbox: https://codesandbox.io/s/toast3-forked-pibtut?file=/src/App.js