1
1
mirror of https://github.com/StanGirard/quivr.git synced 2024-12-29 22:32:40 +03:00
quivr/frontend/lib/components/ui/Toast/hooks/useToastBuilder.ts
Zineb El Bachiri 1d7bc8a5bc
Devx/add linter rules ()
* remove duplicate import

* 🚧 add new linter configuration

* 🧑‍💻  add and run prettier

* 🐛 add babel parser for linter

* 🧑‍💻 add lint-fix command

* 🚨 use lint-fix

* 🚨 remove 'FC' as a type. Use const and JSX.Element

* 🚨 enforce arrow function rule from linter

* 🔥 delete unused file

* 🚨 adding /* eslint-disable */ in failing files

* 💩 add ts-expect-error to Victory components
2023-06-15 11:52:46 +02:00

36 lines
857 B
TypeScript

/* eslint-disable */
import { useState } from "react";
import { ToastContent, ToastData, ToastPublisher } from "../domain/types";
import { generateToastUniqueId } from "../helpers/generateToastUniqueId";
// ⚠️ You should not probably import this. use `useToast` instead
export const useToastBuilder = () => {
const [toasts, setToasts] = useState<ToastContent[]>([]);
const toggleToast = (value: boolean, toastId: string) => {
setToasts((toasts) =>
toasts.map((toast) => {
if (toast.id === toastId) {
toast.open = value;
}
return toast;
})
);
};
const publish: ToastPublisher = (newTost: ToastData) => {
setToasts((toasts) => [
...toasts,
{ ...newTost, open: true, id: generateToastUniqueId() },
]);
};
return {
publish,
toggleToast,
toasts,
};
};