Build a Reusable Toast Notification System
Toast notifications are a common UI pattern used to provide users with transient, non-blocking feedback about an operation's success, failure, or general information. They appear for a short period and then automatically disappear, or can be dismissed manually. Implementing a robust and reusable toast notification system is a fundamental skill for front-end developers, ensuring a good user experience without interrupting workflows.
Your task is to build a reusable Toast Notification system for a React application. You are provided with a basic component structure; your goal is to fill in the missing logic and styling.
ToastProvider component to manage the state of all active toasts and make the addToast function available throughout the application via the ToastContext.useToast Hook: The useToast hook is already provided; ensure it correctly consumes the ToastContext.Toast component. Each toast should:
message.type (e.g., 'success', 'error', 'info').toasts array in state.role="alert", aria-live="assertive") for the toast elements to ensure screen readers announce the messages.App.tsx successfully triggers new toasts via the useToast hook.ToastProvider and useToast hook.Constraints
useState, useEffect, useCallback, useContext).ToastProvider wraps the entire application, as provided in the starter code.ToastProvider and Toast components are structured, how responsibilities are separated, and the effective use of the useToast hook.setTimeout and clearTimeout for automatic dismissal to prevent memory leaks and unexpected behavior.Loading editor...