Update an existing toast using toast.update
To update an active toast, use the
toast.update method. You must provide the toastId of the toast you wish to modify. When updating, existing toast options and content are inherited unless explicitly overridden in the update object.import { toast } from 'react-toastify';
function Example() {
const toastId = React.useRef(null);
// Create a toast and store its ID
const notify = () => {
toastId.current = toast("Hello", { autoClose: false });
};
// Update the toast using the stored ID
const update = () => {
toast.update(toastId.current, { type: "info", autoClose: 5000 });
};
return (
<div>
<button onClick={notify}>Notify</button>
<button onClick={update}>Update</button>
</div>
);
}