Skip to the page

Overlays and disclosure widgets · mid

Toast / notification queue

A toast system exposes a global API (toast.success('Saved')) backed by a queue that shows at most a few toasts, auto-dismisses each with a timer that pauses on hover or focus, announces politely to screen readers, and cleans up every timer.

The notes

What you must know

  • API: toast(message, { type, duration, action }) callable from anywhere: a provider + context, or a small external store with subscribe (works outside React too, e.g. from an API client).
  • Queue: maxVisible (e.g. 3); extra toasts wait; dismissing one promotes the next; optionally dedupe the same message.
  • Timers: one per visible toast; pause on mouse enter or focus, resume with the remaining time; clear on dismiss and on unmount.
  • Rendering: a portal in a fixed corner; stacking/animation (respect prefers-reduced-motion).
  • Accessibility: role='status' (aria-live='polite') for info, role='alert' for errors; don't move focus to the toast; give enough time to read, and a way to dismiss; actions like 'Undo' must be keyboard reachable.
  • React Native variant (Zepto): the same queue with an absolutely positioned container above navigation, safe-area aware.
  • Extras: positions, max length, promise toasts (loading → success/error).

The red pen

Common traps: mistake → fix

  • Mistake: setTimeout without clearing

    Fix: setState on unmounted toasts and leaks.

  • Mistake: Unlimited visible toasts

    Fix: they cover the screen.

  • Mistake: role='alert' for every toast

    Fix: interrupts screen-reader users constantly.

  • Mistake: Global mutable array without subscribers

    Fix: the UI doesn't update.

Easy to hard

Questions interviewers ask, easy to hard

  1. Build a toast system with success, error and info types.
  2. Only 3 visible at a time; the rest wait.
  3. Pause the timer when the user hovers.
  4. Call toast() from a non-React module (API client).

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview