This repository has been archived on 2026-02-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
synthetic-consumer-data/context/toast/ToastProvider.tsx

24 lines
624 B
TypeScript

import React, { useState, useCallback } from 'react';
import { Toast, ToastContext } from './ToastContext';
export const ToastProvider: React.FC<{ children: React.ReactNode }> = ({
children
}) => {
const [toasts, setToasts] = useState<Toast[]>([]);
const showToast = useCallback((message: string) => {
const id = Date.now();
setToasts(prev => [...prev, { id, message }]);
setTimeout(() => {
setToasts(prev => prev.filter(toast => toast.id !== id));
}, 3000);
}, []);
return (
<ToastContext.Provider value={{ showToast, toasts }}>
{children}
</ToastContext.Provider>
);
};