EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
useToast.js
Go to the documentation of this file.
1import { useState, useCallback } from 'react';
2
3export function useToast() {
4 const [toasts, setToasts] = useState([]);
5
6 const showToast = useCallback((message, type = 'info', duration = 5000) => {
7 const id = Date.now() + Math.random();
8 const toast = { id, message, type, duration };
9
10 setToasts(prev => [...prev, toast]);
11
12 return id;
13 }, []);
14
15 const hideToast = useCallback((id) => {
16 setToasts(prev => prev.filter(toast => toast.id !== id));
17 }, []);
18
19 return {
20 toasts,
21 showToast,
22 hideToast
23 };
24}