ERP-node/frontend/hooks/use-toast.ts

28 lines
666 B
TypeScript

import { useCallback } from "react";
import { toast as sonnerToast } from "sonner";
interface ToastOptions {
title?: string;
description?: string;
variant?: "default" | "destructive";
duration?: number;
}
export const useToast = () => {
const toast = useCallback(({ title, description, variant = "default", duration }: ToastOptions) => {
if (variant === "destructive") {
sonnerToast.error(title || "오류", {
description,
duration: duration || 4000,
});
} else {
sonnerToast.success(title || "성공", {
description,
duration: duration || 4000,
});
}
}, []);
return { toast };
};