Props are what a parent hands to a child, like arguments to a function. The child can’t change them. State is the component’s own memory that it can change, and changing it makes React re-draw the component.
Say it like this in the interview
“Props are read-only inputs passed from parent to child. State is data owned by a component, updated with a setter, which triggers a re-render. When two siblings need the same data, I lift the state up to their common parent and pass it down as props.”
setCount doesn’t change count right now; it requests a re-render with the new value. Within this click, count is a frozen snapshot: 0. Both calls say “set to 0 + 1”, so the result is 1. To build on the latest value, pass a function: setCount(c => c + 1).
Say it like this in the interview
“Logs 0 and count becomes 1. State updates are batched and each render sees a snapshot. Both calls compute 0 + 1. The updater form setCount(c => c + 1) uses the pending value, so calling it twice gives 2.”
React keeps a lightweight copy of what the screen should look like. When state changes, it builds a new copy, compares it with the old one, and changes only the parts of the real page that differ.
Say it like this in the interview
“Rendering produces a tree of React elements. Reconciliation diffs the new tree with the previous one, using element type and key to decide what to reuse, then the commit phase applies minimal DOM changes. The Fiber architecture lets React split that work and prioritise urgent updates.”
filters is a new object on every render. React compares dependencies by identity, sees a “different” object each time, re-runs the effect, which sets state, which re-renders, which creates a new object… a loop.
Say it like this in the interview
“The dependency is an object recreated every render, so the effect always re-runs, sets state and re-renders. I depend on the primitive values instead, [category], and build the object inside the effect, or memoise it with useMemo. I’d also add an AbortController to cancel stale requests, or use a data library like TanStack Query.”
Traps that make people fail
Silencing the eslint exhaustive-deps rule instead of fixing the dependency.
useEffect(() => {
const controller = new AbortController();
fetch('/api/search?q=' + encodeURIComponent(query), { signal: controller.signal })
.then(r => r.json())
.then(setResults)
.catch(err => { if (err.name !== 'AbortError') setError(err); });
return () => controller.abort(); // cleanup cancels the old request
}, [query]);
In simple words
Requests don’t come back in the order they were sent. The response for “rea” arrives after “react”, overwriting the right results.
Say it like this in the interview
“It’s a race condition between responses. The effect cleanup should abort the previous request with AbortController, or ignore stale results with a flag. Debouncing input reduces requests too. Libraries like TanStack Query handle this by keying requests.”
React’s Strict Mode deliberately mounts, unmounts and re-mounts components in development to reveal effects that don’t clean up properly. It doesn’t happen in production.
Say it like this in the interview
“It’s intentional Strict Mode behaviour in development. The fix isn’t to disable it, but to make the effect resilient: add cleanup, like aborting the request or unsubscribing. If an effect can’t safely run twice, it probably shouldn’t be an effect, for example a POST on mount belongs in an event handler.”
useEffect runs after the browser has painted the screen. useLayoutEffect runs before the paint, so you can measure and adjust layout without a visible flicker, but it blocks painting.
Say it like this in the interview
“useEffect is deferred until after paint and suits data fetching, subscriptions and logging. useLayoutEffect runs synchronously after DOM mutations but before paint, used for measuring elements or positioning tooltips. Overusing it hurts performance.”
Keys are name tags React uses to match old items with new ones. If you use positions as name tags and then insert at the top, every item gets the wrong name tag, so React reuses the wrong component, and things like typed input text appear in the wrong row.
Say it like this in the interview
“Keys identify items between renders. Index keys break when the list is reordered, filtered or prepended: component state and DOM like input values attach to the wrong item. I use stable IDs from the data. Index is only acceptable for static lists that never change order.”
Render = React figures out what should change (can be paused, restarted, or thrown away). Commit = React actually updates the page and runs effects (always finishes in one go).
Say it like this in the interview
“The render phase calls components to compute the new tree; it must be pure because, with concurrent rendering, it can be interrupted or run more than once. The commit phase applies DOM mutations, runs layout effects synchronously, then passive effects. That’s why side effects never belong in the component body.”
Suspense lets you show a fallback (spinner, skeleton) for a part of the page that’s still loading code or data, while the rest is already visible.
Say it like this in the interview
“<Suspense fallback> shows a fallback while children suspend, whether lazy-loaded components with React.lazy, data via the use hook or a framework. With streaming SSR, each boundary can stream in separately. Placing boundaries well avoids both blank pages and spinner overload.”
They mark some updates as “not urgent”, so typing stays instant while a slow list re-renders in the background.
Say it like this in the interview
“Concurrent features: startTransition marks a state update as low priority, so urgent updates like typing interrupt it, and isPending shows progress. useDeferredValue gives a lagging copy of a value for expensive rendering. They help with slow rendering, not slow networks.”
A portal renders a component somewhere else in the page (usually at the end of <body>) while it still behaves like a normal child in React.
Say it like this in the interview
“createPortal(children, domNode) renders outside the parent’s DOM hierarchy while keeping React context and event bubbling. Used for modals, tooltips and dropdowns to escape overflow: hidden and stacking-context issues.”
Give the component a key based on that prop. When the key changes, React throws the old component away and creates a fresh one with fresh state.
Say it like this in the interview
“Use <Profile key={userId} userId={userId} />. Changing the key remounts the component, resetting all its state, cleaner than a useEffect that resets state after rendering stale data.”
A component re-renders when its state changes, its parent re-renders, or a context it uses changes. memo says “skip me if my props didn’t change”. But a new function or object prop is “changed” every time, so useCallback/useMemo keep the same function/object between renders.
“State change, parent re-render, or context change. React.memo skips re-rendering when props are shallowly equal; useCallback and useMemo keep referential stability so memo actually works, and useMemo avoids recomputing expensive values. I only add them after measuring with the React Profiler, because they have a cost too. The React Compiler can now do much of this automatically.”
One big Context with lots of values means any change updates everyone who reads it, even if they only care about one value.
Say it like this in the interview
“Split the context by concern, for example state and dispatch separately; memoise the value object with useMemo so it doesn’t change every render; keep fast-changing values out of context; or use a store with selectors like Zustand, so components subscribe only to the slice they need.”
A build tool that automatically adds the memoisation you’d otherwise write by hand with useMemo, useCallback and memo.
Say it like this in the interview
“It analyses components at build time and memoises values and JSX automatically where safe, reducing manual useMemo and useCallback. It relies on components following the rules of React: pure render, no mutation of props or state. It doesn’t fix architectural issues like huge contexts.”
The browser struggles with 10,000 DOM elements. Show only the rows currently visible.
Say it like this in the interview
“Virtualise with TanStack Virtual or react-window, so only visible rows render. Also memoise row components with stable keys and props, paginate or use infinite scroll from the API, and avoid expensive work in each row render. I confirm with the React Profiler.”
Controlled: React state is the source of truth; every keystroke updates state and the input shows state. Uncontrolled: the browser input keeps its own value and you read it when needed (via a ref or form submission).
Say it like this in the interview
“Controlled inputs bind value to state and update it onChange. That’s good for live validation and dependent fields. Uncontrolled inputs use defaultValue and read via refs or FormData, simpler and more performant for big forms; libraries like React Hook Form use that approach. The ‘changing an uncontrolled input to be controlled’ warning means value started as undefined.”
Actions are async functions you pass straight to a form. React tracks pending state and errors for you. useOptimistic shows the result immediately (like a sent message) before the server confirms.
Say it like this in the interview
“A form’s action can be an async function; React handles pending state with useFormStatus, results and errors with useActionState, and resets. useOptimistic renders an optimistic version of state while the action runs, reverting if it fails. With Server Actions, the function runs on the server.”
Hand-writing state for 30 fields is slow and re-renders too much. Use a form library and a schema that describes valid data.
Say it like this in the interview
“React Hook Form with a Zod schema: uncontrolled inputs registered by name for performance, schema validation reused on the server, field-level error messages and accessibility attributes. Server-side validation always runs too, since client validation is only UX.”
Separate two kinds of data. Server state (products, users from an API) belongs in a fetching/caching tool like TanStack Query. UI state (theme, modal open) is small: local state or Context. A global store is for complex client state shared widely.
Say it like this in the interview
“Local state first. Context for rarely-changing global values like theme, locale or the current user, since every consumer re-renders on change. TanStack Query or SWR for server data, with caching, refetching and deduplication. Zustand or Redux Toolkit when there’s complex, frequently updated client state shared across many components.”
Move the data up to the nearest common parent, and pass it down to both children with props, along with a function to change it.
Say it like this in the interview
“Lift state up to the closest common ancestor and pass the value and setter as props. If many layers need it, Context or a store avoids prop drilling, but lifting is the default.”
Passing a prop through many components that don’t use it, only to reach a deep child. Annoying and fragile.
Say it like this in the interview
“Prop drilling is threading props through intermediate components. Solutions: component composition (passing children or elements as props), Context for widely-needed values, or a state library. Composition is often overlooked and keeps components decoupled.”
If you can calculate something from existing state or props, don’t store it separately. Two copies get out of sync, and the effect causes an extra render.
Say it like this in the interview
“It’s redundant derived state: an extra render and a chance of inconsistency. Compute it during render, const fullName = first + ' ' + last, and use useMemo only if the computation is expensive.”
“Lazy initial state reads storage once, guarded with try/catch for bad JSON or disabled storage; an effect writes on change. In SSR I’d guard against window being undefined.”
Only call hooks at the top level of a component or custom hook, never in loops, conditions or after an early return. React remembers hooks by their order; if the order changes, it mixes up which state belongs to which hook.
Say it like this in the interview
“Call hooks unconditionally at the top level of function components or custom hooks. React stores hook state in a list indexed by call order, so conditional calls shift the indexes and corrupt state. The eslint rules-of-hooks plugin enforces it.”
A ref is a box that keeps a value between renders without causing a re-render when it changes. Good for timer IDs, previous values, or flags.
Say it like this in the interview
“useRef returns a mutable object whose .current persists across renders. Besides DOM access, I use it for timeout IDs, the previous value of a prop, or the latest callback to avoid stale closures. Changing it doesn’t trigger a render, so it must not drive what’s displayed.”
The interval callback was created during the first render and remembers that render’s count (0) forever. It keeps setting 0 + 1.
Say it like this in the interview
“A stale closure: the effect runs once and captures count = 0. Fixes: use the updater setCount(c => c + 1), which doesn’t depend on the captured value, or include count in the dependencies and recreate the interval, or store the latest value in a ref.”
Both share logic between components. HOCs wrap a component in another component; hooks let a component pull in logic directly. Hooks are simpler and the modern default.
Say it like this in the interview
“HOCs are functions that take a component and return an enhanced one; they can cause wrapper hell and prop collisions. Custom hooks share stateful logic without changing the component tree and compose more easily. HOCs still appear in older code and for cross-cutting wrappers.”
Group code by feature, not by file type, keep components small and dumb where possible, and put business logic and data access in hooks and services that can be tested separately.
Say it like this in the interview
“Feature-based folders (features/checkout with its components, hooks, api and tests), a shared UI kit, server state via a query library, minimal global client state, route-level code splitting with lazy loading, error boundaries around independent regions so one crash doesn’t blank the page, TypeScript, and tests at the behaviour level with Testing Library. For SEO-heavy apps, a framework like Next.js with server components.”
An error boundary is a safety net around part of the UI: if a component inside crashes while rendering, it shows a fallback instead of a blank page.
Say it like this in the interview
“They catch errors during rendering, lifecycle methods and constructors of children. They don’t catch errors in event handlers, async code like promises and timeouts, server-side rendering, or in the boundary itself. Those need try/catch and error state. Error boundaries are still class components, or a library like react-error-boundary.”
Keep as much as possible on the server (data fetching, static content, heavy libraries) and make only the interactive pieces client components.
Say it like this in the interview
“Server components by default for data fetching and static UI; 'use client' only on leaves that need state, effects, event handlers or browser APIs. Pass server-fetched data down as serialisable props, and pass server components into client components as children to keep them on the server.”
No. SSR renders your whole app to HTML on the server once, then ships all the JavaScript to the browser to make it interactive. Server Components never send their code to the browser at all.
Say it like this in the interview
“SSR produces initial HTML for client components, which then hydrate, so their JS still ships. Server components render only on the server and send a serialised result; their code and dependencies never reach the client. They’re complementary: Next.js uses both.”
Test what the user sees and does (click this, see that), not internal state or implementation details.
Say it like this in the interview
“React Testing Library with Vitest or Jest: render the component, query by role or label like a user would, simulate events with user-event, and assert on visible output. Mock the network with MSW. E2E tests with Playwright cover critical flows.”
Fetching inside useEffect works but you must handle loading, errors, caching and race conditions yourself. Libraries and frameworks do this for you.
Say it like this in the interview
“In a client SPA, TanStack Query or SWR for caching, deduplication, retries and background refetching. In Next.js or other RSC frameworks, fetch in server components. Raw useEffect fetching needs cleanup and race handling, so I avoid it for anything non-trivial.”
Use real HTML elements, label everything, make sure everything works with a keyboard, and test with a screen reader.
Say it like this in the interview
“Semantic elements, labels for inputs, alt text, focus management on route changes and in modals, visible focus styles, ARIA only when native elements can’t do it, sufficient contrast, and testing with axe, keyboard-only navigation and VoiceOver or NVDA.”