Designing UI
Writing a component that works is easy. Designing one that other people can use, that behaves correctly with a keyboard, and that does not collapse under a large list is the actual skill. The questions below run roughly in order of how often they decide a front-end interview.
The 60-second answer
Section titled “The 60-second answer”“Design components around composition, not configuration: take children and slots instead of adding
boolean props. Keep props small, explicit and typed, and let the parent own state. Accessibility is
not optional — semantic elements, labels, keyboard handling, visible focus, and ARIA only where
semantics fall short. Lists need stable keys; forms need one source of truth per field and validation
next to the field. For performance, measure first: memoise only provable hot spots, split routes
rather than micro-components, and defer work you do not need on the critical path. And every UI needs
designed loading, empty and error states, not just the happy path.”
Composition over configuration
Section titled “Composition over configuration”// Configuration creep: every new need adds a boolean.<Card title="User" showAvatar showFooter footerText="..." dense />
// Composition: the caller decides what goes in the slots.<Card> <Card.Header><Avatar src={user.avatar} />{user.name}</Card.Header> <Card.Body>{user.bio}</Card.Body> <Card.Footer><Button>Follow</Button></Card.Footer></Card>- Accept
childrenand named slots (header,footer,actions) rather than flags. - Extend the native element with
React.ComponentPropsWithoutRef<'button'>instead of re-declaring its props. - Forward
refwhere the component wraps a DOM node (in React 19,refis a normal prop). - Spread unknown props onto the underlying element so
aria-*,data-*and handlers work.
Every prop is a contract you maintain, and every boolean doubles the number of states you must render correctly. Keep the public surface small.
Accessibility
Section titled “Accessibility”function Disclosure({ title, children }: { title: string; children: ReactNode }) { const [open, setOpen] = useState(false); const id = useId();
return ( <div> <button type="button" aria-expanded={open} aria-controls={id} onClick={() => setOpen((o) => !o)}> {title} </button> <div id={id} hidden={!open}>{children}</div> </div> );}- Use the right element. A clickable
divneeds a role, tab index and Enter/Space handling — abuttonalready has all of it. - Label every input with
<label htmlFor>oraria-label; placeholder text is not a label. - Never remove focus outlines. Restyle them; keyboard users need to see where they are.
- Manage focus on route and modal changes, and trap it inside a modal.
- Announce dynamic changes with
aria-live="polite". - Respect
prefers-reduced-motion, keep contrast at WCAG AA, and test with a keyboard and a screen reader.eslint-plugin-jsx-a11ycatches the mechanical errors.
// Uncontrolled: the DOM owns the value; read it on submit. Fewer re-renders.<form onSubmit={(e) => { e.preventDefault(); onSearch(String(new FormData(e.currentTarget).get('q') ?? ''));}}> <label htmlFor="q">Search</label> <input id="q" name="q" type="search" /></form>// Controlled: React owns the value; needed for live validation and derived UI.const invalid = email.length > 0 && !email.includes('@');
<input id="email" type="email" value={email} aria-invalid={invalid} aria-describedby={invalid ? 'email-error' : undefined} onChange={(e) => setEmail(e.target.value)} />{invalid && <p id="email-error" role="alert">Enter a valid email</p>}One source of truth per field; validate on blur or submit, not on every keystroke; disable submit only
when the reason is obvious; show errors next to the field and wire them with aria-describedby. For
complex forms, a schema (Zod) plus a form library shares validation with the server.
Lists and performance
Section titled “Lists and performance”- Keys must be stable, unique among siblings, and not the array index unless the list is static.
Keys are not props — a component cannot read
key, so pass the id separately if it needs it. - Virtualise long lists (
@tanstack/react-virtual) rather than rendering thousands of rows.
The performance order matters: measure, then fix the actual bottleneck.
- Render less. Move state down, split components so a keystroke does not re-render a tree, pass
childrenthrough unchanged so they keep identity. - Defer non-urgent work.
useDeferredValuefor search results,useTransitionfor expensive transitions. - Memoise only what profiling shows.
memofor components re-rendering with identical props,useMemofor expensive computation,useCallbackwhen a function identity is a dependency. - Split the bundle by route, not by micro-component, with
React.lazyplusSuspenseor the framework’s route-level splitting. - Load assets well.
loading="lazy"for below-the-fold images, explicit dimensions to avoid layout shift.
function Search({ query }: { query: string }) { const deferred = useDeferredValue(query); const results = useMemo(() => filterAll(deferred), [deferred]); return <Results items={results} stale={deferred !== query} />;}Loading, empty and error states
Section titled “Loading, empty and error states”Every asynchronous UI has at least four states: loading, empty, error, success. Design them.
if (isPending) return <ListSkeleton rows={5} />;if (error) return <ErrorPanel message={error.message} onRetry={refetch} />;if (!data.length) return <EmptyState action={<Button>Create one</Button>} />;return <List items={data} />;Skeletons should match the final layout to avoid a shift. Errors need a recovery path, not just a message. Empty states should explain what would appear and how to make it appear. Wrap route-level subtrees in error boundaries; an unhandled render error otherwise blanks the app.
Follow-up questions
Section titled “Follow-up questions”- How do you make a custom dropdown keyboard-accessible?
- When is a controlled input the wrong choice?
- Why is
React.memosometimes slower than no memo at all? - How would you render 50,000 rows?
- What is the difference between
useDeferredValueand debouncing?
Common traps
Section titled “Common traps”- Using
indexas a key in a sortable list. State and focus attach to the wrong row. aria-labelon adivthat should be abutton. Semantics first, ARIA second.- Disabling submit with no explanation. Users cannot tell what is wrong.
- Memoising everything by default. Cost, stale closures, no measured benefit.
- Only designing the happy path. Loading and error states are where products feel unfinished.
- Fetching in
useEffectwithout cancellation. State after unmount, and races where an older response overwrites a newer one.