micro/packages/web/src/components/toast/useToasts.tsx

13 lines
338 B
TypeScript

import { useContext } from 'react';
import { ToastContext } from './context';
export const useToasts = () => {
const createToast = useContext(ToastContext);
if (!createToast) {
if (typeof window === 'undefined') return () => {};
throw new Error('useToasts must be used within a ToastProvider');
}
return createToast;
};