Skip to content
Tech Interview Prep
Technical interview guide

React Fundamentals

The rendering model, state as a snapshot, keys and component identity, effects as synchronization, memoisation, and the client boundary.

Read
44 min
Practice MCQs
25
Interview Q&A
25
Edition
v3
Editorial status
Reviewed

Scope: React 19, including automatic batching from React 18 and the Server Component model as implemented by React 19 and Next.js 16.

Curated: · Written: · Reviewed:

25 questions

MCQ-22On React 18, a 30-field application form keeps its whole draft in one useState object, and the Title field is written as <input value={draft.title} /> with no other props. QA reports that the field refuses typing, and React logs that a value prop without an onChange handler renders a read-only field. The field sits next to a character counter and a Save button that stays disabled until the title reaches 5 characters, and both must update on every keystroke. Which change meets that requirement?
MCQ-4A counter component holds `const [count, setCount] = useState(0)` and renders `<button onClick={handleClick}>{count}</button>`. The handler is: ```jsx function handleClick() { setCount(count + 1); setCount(count + 1); setCount(count + 1); console.log(count); } ``` The user clicks the button once. What does the console print, and what does the button show?
MCQ-5A counter component's click handler calls `setCount(count + 1)` three times, and one click moves the display from 0 to 1. Replacing those three calls with `setCount(c => c + 1)` makes the same click move it to 3. Which statement explains the difference?
MCQ-6A component is mounted with React 18's `createRoot` (StrictMode off) and logs every render. Its click handler is async: ```jsx async function onClick() { setCount(c => c + 1); setFlag(f => !f); await fetch('/api/thing'); // resolves normally setCount(c => c + 1); setFlag(f => !f); } ``` The user clicks once and the fetch resolves. How many times does the component render?
MCQ-18A panel keeps a click count in a ref so that counting does not re-render it, and a second number in state that is only meant to change on Save. Nothing else in the app touches state: function Panel() { const clicksRef = useRef(0); const [saved, setSaved] = useState(0); return ( <> <p>Clicks: {clicksRef.current} Saved: {saved}</p> <button onClick={() => { clicksRef.current += 1; }}>Click</button> <button onClick={() => setSaved((s) => s + 1)}>Save</button> </> ); } An engineer presses Click three times, then Save once. What does the paragraph read during the three presses, and what does it read straight after the Save press?
MCQ-23A component calls useState twice inside an if/else, with the two calls written in opposite order in the two branches; each branch makes exactly two hook calls and destructures into the same two names. Which statement describes how React decides what each call receives after the branch flips?
MCQ-3`<ProfileCard user={user} />` renders `<input value={name} onChange={e => setName(e.target.value)} />` from `const [name, setName] = useState(user.name)`, and the parent renders `<h1>{user.name}</h1>`. The parent polls `/me` every 2 s and passes the response straight through as `user`; over 6 polls the server returns 6 different names. The `<h1>` shows the newest name each time, the input still shows the name from the first poll, and typing in the input never changes the `<h1>`. Which change fixes both symptoms?
MCQ-7A `<Preview>` component receives a `docId` prop and renders a parsed document. It starts as `const [doc, setDoc] = useState(loadDoc(docId))`, where `loadDoc` takes about 80 ms. Because that call runs on every render, a teammate changes it to `useState(() => loadDoc(docId))`. Now selecting a different document in the sidebar leaves the preview showing the old document. What change makes the preview update when `docId` changes without re-parsing on every render?
MCQ-8A team is refactoring a component that filters and counts items received from a parent prop. When should this transformed data be computed directly during render as derived state rather than stored in a separate useState?
MCQ-2A parent component keeps `rows` in state in the order they were entered -- Alice (10 points), Bob (30), Carol (20) -- and renders `<Ranked rows={rows} />` followed by `<Recent rows={rows} />` in the same commit. `Ranked` opens with `rows.sort((a, b) => b.score - a.score)` and renders each row in an ordered list; `Recent` renders the array it receives without sorting. The app runs on React 18 and is mounted under `StrictMode` in development. What does `Recent`'s list contain on the first paint?
MCQ-1Production React 18 build, StrictMode off. A profile page keeps the selected id in state, and a "similar profiles" feed pushes an update into that same state every 30 s, so each feed update re-renders the page and the panel under it. The panel sits at the same position in every render with no key: `<ProfilePanel id={selectedId} onClose={() => setSelectedId(null)} />`. `ProfilePanel` calls `analytics.track("profile_viewed", id)` in its component body. In one session the page mounts with `selectedId = 'A'`, two feed updates land, the user selects `'B'`, then one more feed update lands. Analytics shows 5 `profile_viewed` events; product wants one per profile opened, which is 2. Which change gets exactly 2?
MCQ-11A `Dashboard` component declares a `SearchBox` function inside its own body and renders it below a controlled input bound to `query`: ```jsx function Dashboard() { const [query, setQuery] = useState(''); function SearchBox() { const [text, setText] = useState(''); return <input value={text} onChange={e => setText(e.target.value)} />; } return ( <> <input value={query} onChange={e => setQuery(e.target.value)} /> <SearchBox /> </> ); } ``` Typing in the top input clears whatever the user had already typed into `SearchBox`. What is the cause?
MCQ-10A dynamic list of editable user rows allows insertion, reordering, and deletion. An engineer proposes using the array index as the key for each item component. What failure mode directly occurs when modifying the list under this design?
MCQ-9A 300-row table renders `<Row key={index} {...row} />` from `rows.map((row, index) => ...)`. Each Row renders an uncontrolled `<input defaultValue={row.note} />`, and most rows have an empty note, so note values repeat. Clicking the 'Name' header sorts `rows` by name and re-renders. After the sort, text the user typed into a row shows up in a different row. Which change removes the misplacement?
MCQ-13An effect is declared as `useEffect(fn, [config])`, where `config` is a prop object. When the parent re-renders and passes a new object with identical fields, the effect re-runs; when the parent re-renders and passes the same object instance, the effect is skipped. Which statement describes the comparison React performed?
MCQ-12A dashboard component subscribes to a live metrics store from an effect: `useEffect(() => { store.subscribe(roomId, onMetrics); }, [roomId])`. Operators report that after moving through 40 rooms the store shows 40 live listeners, and the component re-renders on updates for rooms it is no longer displaying. Which change fixes the leak?
MCQ-16A chat app opens a WebSocket per room in an effect and never closes it: ```jsx useEffect(() => { const c = createConnection(roomId); c.connect(); }, [roomId]); ``` In a development build with StrictMode on, a user opens room "a" and then switches to room "b". The server counts one live connection per successful `connect()` call. How many live connections does it hold once the switch settles?
MCQ-14A chart component mounts at t=0 with `range = 30`; at t=60 ms the user switches the range to 7. It is a production build, so the mount effect runs once, and the chart starts with no data. ```jsx useEffect(() => { fetchSeries(range).then(setData); // no cleanup returned }, [range]); ``` The 30-day response arrives 350 ms after its request is sent; the 7-day response arrives 80 ms after its request is sent. What does the chart display, and when?
MCQ-15According to React's guidance in 'You Might Not Need an Effect', which implementation pattern represents an unnecessary effect that should be refactored?
MCQ-17A dropdown menu is positioned above its anchor by measuring the menu's height with getBoundingClientRect and storing the offset in state. The app is client-rendered, and one frame of the menu at the wrong position is visible as a jump on open. Where does the measure-and-set work go?
MCQ-19A search page keeps its query state and a 20,000-row rows prop in one component, which computes const sorted = useMemo(() => rows.slice().sort(byName), [rows, query]), where sort(byName) reads only rows. Profiling shows that pass running at about 30 ms on every keystroke, roughly 10 keystrokes per second, even though rows never changes while the user types, and the input visibly drops frames. Which change removes the 30 ms pass from the keystroke path?
MCQ-20A table renders 500 rows, each row rendering 4 `Cell` components; both `Row` and `Cell` are wrapped in `React.memo`. The parent holds `hoveredId` in state and re-renders on every mouse move: ```jsx <Row key={row.id} row={row} // stable object from a useMemo over the fetched data onPick={onPick} // stable useCallback hovered={hoveredId === row.id} density={density} // module-level constant /> ``` `Row` passes `hovered` down to each `Cell`, along with `value` (string), `width` (number) and `align` (a constant string). The mouse moves from row 7 to row 8. How many `Cell` components re-render?
MCQ-21A dashboard renders `<SettingsContext.Provider value={{ user, theme, lastSyncAt }}>` in a component that also holds `lastSyncAt` in state, updated by a polling hook every 5 seconds. Of the 40 components calling `useContext(SettingsContext)`, 2 read `lastSyncAt` and 38 read only `user` or `theme`. DevTools' highlight-updates shows all 40 flashing on every poll. Which change stops the 38 from re-rendering on each poll while the 2 keep updating?
MCQ-24A React 18 page renders `<ErrorBoundary fallback={<ErrorPage/>}><Suspense fallback={<Spinner/>}><Profile/></Suspense></ErrorBoundary>`. Profile reads from a Suspense-compatible cache: on a cold read it throws a promise, and when the fetch for /api/profile returns 500 the cache stores the rejection and re-throws the error on the next render. A user opens the page with a cold cache and the request fails. What does the user see?
MCQ-25A Next.js App Router route at /dashboard (React 18+) renders a server-fetched dataset into <Chart>, which imports a 300 KB charting library, alongside <Toggle>, which uses useState. The build reports 340 KB of First Load JS for the route, and page.jsx starts with "use client". Which change removes the charting library from the client bundle?