Files
docmost/client/src/components/ui/custom-toaster.tsx
T
Philipinho 9b682c8af5 vite
* replace next with vite
* disable strictmode (it interferes with collaboration in dev mode)
2023-10-20 17:12:08 +01:00

20 lines
528 B
TypeScript

import t, { Toaster, useToasterStore } from "react-hot-toast";
import { useEffect, useState } from "react";
export default function CustomToaster() {
const { toasts } = useToasterStore();
const TOAST_LIMIT = 3;
const [toastLimit, setToastLimit] = useState<number>(TOAST_LIMIT);
useEffect(() => {
toasts
.filter((tt) => tt.visible)
.filter((_, i) => i >= toastLimit)
.forEach((tt) => {
t.dismiss(tt.id);
});
}, [toastLimit, toasts]);
return <Toaster position={"top-right"}/>;
}