Build a Flexible Toast Notification System
In a dynamic platform like Livspace, providing immediate and clear feedback to users is crucial for a smooth user experience. Whether it's confirming a successful action (e.g., 'Design saved!'), alerting to an error ('Failed to load data'), or providing general information, toast notifications serve as a non-intrusive way to communicate with the user. This problem challenges you to build a reusable and robust toast notification system, demonstrating your skills in component architecture, state management, and UI implementation.
Your primary goal is to build a ToastProvider and a useToast hook that allows any component within the application to trigger and manage toast notifications.
ToastProvider Component: Create a top-level component that will manage the state of all active toasts and render them in a designated area of the screen.useToast Hook: Implement a custom React hook that provides methods to addToast (trigger a new toast) and dismissToast (manually remove a toast by ID).Toast Component: Design a individual Toast component responsible for displaying a single notification, including its message, type, and a close button.success, error, info, and warning. Each type should have a visually distinct appearance (e.g., different background colors).ToastProvider at a high level in the component tree.useToast hook to trigger new notifications.addToast with different types (success, error, info, warning) results in visually distinct toasts.Constraints
ToastProvider, useToast hook, and Toast components are structured, demonstrating clear separation of concerns.useState/useRef/useEffect hooks to manage toast lifecycle and state.Loading editor...