Remove programmatically
Ability to remove toasts programmatically, allowing for precise control over which notifications should be dismissed.
Example
remove one toast
import { toast, Toaster } from "@toastup/react";
import "@toastup/react/style";
import { useState } from "react";
export function RemoveProgrammaticallyExample() {
const [ids, setIds] = useState<string[]>([]);
const handleAddClick = () => {
const id = toast.add({ autoHide: 20000 });
setIds(ids => [...ids, id]);
};
const handleRemoveClick = () => toast.remove(ids.pop());
const handleRemoveAllClick = () => {
toast.remove();
setIds([]);
};
return (
<div>
<button onClick={handleAddClick}>Add toast</button>
<div className={styles.buttonsRow}>
<button onClick={handleRemoveClick}>Remove last</button>
<button onClick={handleRemoveAllClick}>Remove all</button>
</div>
<Toaster />
</div>
);
}