call(back)

What Do You Check Before Calling a UI Component Done?

You have just finished a UI coding question — a tabs component, say, or a like button — and there are ten minutes left. What do you check before you say it is done?

Talk for about three minutes: the checklist in the order you would actually run it, and for each item, what the fix looks like when it fails.

Hints

Hint 1

Start from what the interviewer will do next: open a second instance, press Tab, type a long name, pull the network. Each of those is a section of the list.

Hint 2

Order it from cheapest to check to most expensive: labels and <button>s take seconds; network states and keyboard flows take minutes.

Solution

Show the approach

The checklist

Instances. Can two live on one page? No ids baked into the markup, no module-level state, options in (labels, callbacks, defaults) and a small API out. In plain JavaScript that is init(root, options); in React it is props and useId. → Tabs: initTabs(node)

State. List the state fields and strike every one you can compute from the others: the selected index, not a boolean per tab; the leaves, not every parent. When several fields change together, one reducer. → Nested Checkboxes, Multi-Step Form With a Shared Store

HTML. A <button> for anything clickable, a <form> around inputs so Enter submits, a <label> wired to every input by for, the right type (email, number, search), headings in order with one h1. A click handler on a <div> is the fastest way to lose the round. → Sign-Up Form

Forms. Native attributes first (required, minlength, pattern, min/max), JavaScript for the rules they cannot state; errors beside the field and linked by aria-describedby; preventDefault only because you are sending the request yourself; the button locked while it is out. → Sign-Up Form, Star Rating in a Form

Network. Every request shows pending, failure and success. A second click cannot send a second request. A slow old response cannot overwrite a newer one. Repeated queries hit a cache, and typing is debounced. Optimistic updates are the advanced version: flip first, revert on failure. → Like Button, Typeahead with Keyboard Navigation

Keyboard and screen reader. Tab reaches every control in a sensible order, arrows move inside composites, Escape closes, focus is visible. Icon-only buttons get aria-label; state goes in aria-pressed, aria-selected or aria-expanded; changes are announced; images have alt; nothing depends on colour alone. → A Tooltip Library From data Attributes

CSS. Plain CSS with custom properties, one class per block and element, no #id selectors inside anything reusable, images fitted with object-fit, touch targets at least 44 px, a media query if it has to work on a phone. → Image Carousel With One Image Element

Edge cases. The empty list says so instead of looking stuck. A long label wraps or truncates instead of pushing the layout around. Ten thousand rows get paged or windowed. → Data Table I, Windowed List

Performance. Debounce and throttle the chatty events, memoise repeated work, load heavy code and data when first needed, prefetch what is about to be needed. → Implement debounce(), Load CSS on Demand

Security. User text goes through textContent or JSX, never innerHTML; anything that lands in a URL goes through encodeURIComponent. → How Do You Secure a Site?

Strings and locales. No hard-coded labels inside the component (pass them in), a layout that survives text twice as long, logical properties (margin-inline-start) so right-to-left needs no second stylesheet.

Worth saying out loud

  • Run the list as you build, not at the end: try each feature in the browser before starting the next, because a bug caught now costs a minute and the same bug later costs ten.
  • Name what you are skipping. Saying "the empty state and long names are next" earns most of the credit for handling them.

Assistant

Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.

Similar Problems6