mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
28 lines
785 B
TypeScript
28 lines
785 B
TypeScript
import { useCallback } from 'react';
|
|
import toast from 'react-hot-toast';
|
|
|
|
interface ToastOptions {
|
|
title?: string;
|
|
description?: string;
|
|
variant?: 'default' | 'destructive';
|
|
duration?: number;
|
|
}
|
|
|
|
export function useToast() {
|
|
// Stable identity so callers can safely list `toast` in effect/callback deps
|
|
// without re-firing on every render.
|
|
const showToast = useCallback((options: ToastOptions) => {
|
|
const { title, description, variant = 'default', duration = 3000 } = options;
|
|
|
|
const message = title ? `${title}${description ? ': ' + description : ''}` : description || '';
|
|
|
|
if (variant === 'destructive') {
|
|
toast.error(message, { duration });
|
|
} else {
|
|
toast.success(message, { duration });
|
|
}
|
|
}, []);
|
|
|
|
return { toast: showToast };
|
|
}
|