Toast NotificationLoading saved progress…

Toast Notification

A toast notification is a short status message that appears without interrupting the current task and dismisses itself after a delay. Build one in React that confirms a save, supports an immediate manual close, and restarts its countdown when it is shown again.

Signature

Implement the App component in App.tsx. Keep the toast's visibility in React state and keep its timeout id in a ref so every handler can cancel the same pending callback.

Examples

  • Click Show notification: one toast reading Saved successfully appears with a dismiss button.
  • Leave it open: it disappears after 3 seconds.
  • Click Show again before 3 seconds pass: the existing toast remains and gets a fresh 3-second countdown.
  • Click the × button: the toast disappears immediately and the pending auto-dismiss is cancelled.

Notes

  • Keep one toast. You do not need a queue for this exercise.
  • Use one timeout. Clear the old timeout before scheduling the next one.
  • Keep handles out of state. Store the timeout id in useRef; it is not rendered data.
  • Clean up. Clear the timeout when the component unmounts.
  • Make status accessible. Give the toast role="status" and an aria-live="polite" region; label the icon-only close button.
WE’RE LISTENING

Help make UIReady better

Found a bug or have an idea? Tell us about it.

Up to 3 files · 5 MiB each · JPG, PNG, WebP, MP4, WebM, MP3, M4A or WAV