Build a Resilient Toast Notification System
In modern web applications, providing timely and non-intrusive feedback to users is crucial for a smooth user experience. Toast notifications are a common pattern for displaying transient messages (e.g., "Action successful!", "Item added to cart") without interrupting the user's workflow. This problem challenges you to build a foundational toast notification system, focusing on state management and component composition.
Your goal is to implement a reusable and robust toast notification system in React. This involves creating a ToastProvider component, a useToast custom hook, and a Toast display component.
ToastProvider: This component should manage the state of all active toasts. It will wrap your application (or a part of it) and provide the showToast functionality via React Context.useToast hook: This custom hook will allow any component within the ToastProvider's scope to easily trigger new toast notifications.Toast component: This component will be responsible for rendering an individual toast message, including a dismiss button.showToast is called, a new toast should appear on the screen.styles.css.App successfully triggers a new toast notification.Constraints
react-toastify). The goal is to implement the core logic yourself.display: none or opacity transitions.createContext, useContext, and useState/useEffect/useCallback.ToastProvider and Toast components.Loading editor...