React interview questions and answers for React developers
React interview questions focus on how rendering works: when a component re-renders, how state updates are batched, what effects are for, and why keys matter. Expect concept questions, a "what does this component show after one click" snippet, a live build of a small component, and for senior roles questions on performance, data fetching and app structure. The strongest answers explain React's model first and the API second.
By Evin JohnPublished 7 min read
How React developer interviews are run
A React developer interview usually sits inside a frontend loop: one JavaScript round, one React round, sometimes a take-home, and a design discussion for senior candidates. The React round tends to be practical. You may get a component with a bug to fix, a small feature to build in a sandbox (a searchable list, a form with validation, tabs, a modal), or a set of questions about what a snippet renders.
- Concept questionsRendering, state, effects and keys. Interviewers listen for the mental model, such as "state is a snapshot per render".
- Predict the renderA component with a few state updates or an effect. Say what the screen shows and what is logged, and why.
- Build in a sandboxForty to sixty minutes on a small feature with loading, empty and error states. Structure and naming are graded along with correctness.
- Senior discussionHow you would organize state, fetch data, split bundles and test a large app, with trade-offs from your experience.
React fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What happens when state changes? | Render model | React calls the component again to get new JSX, compares it with the previous result, and applies only the needed DOM changes in the commit phase. |
| Props versus state? | Data flow | Props come from the parent and are read-only; state is owned by the component and changed through its setter. Data flows down, events flow up through callbacks. |
| What does JSX compile to? | Under the hood | Function calls that create element objects (jsx() with the modern transform, React.createElement before). Elements are plain descriptions, not DOM nodes. |
| Why do list items need a stable key? | Reconciliation | Keys tell React which item is which between renders. Index keys break when items are inserted, removed or reordered: input values and state follow the position, not the item. |
| Controlled versus uncontrolled inputs? | Forms | Controlled inputs take value from state and update through onChange. Uncontrolled inputs keep their value in the DOM and are read through a ref or form data. |
| What does lifting state up mean? | State placement | Move shared state to the closest common parent and pass it down, so two siblings stay in sync. |
| What re-renders a component? | Render triggers | Its own state change, its parent re-rendering, or a context value it reads changing. A prop change alone is not the trigger; the parent's render is. |
| What is a fragment for? | JSX structure | Returning several elements without an extra DOM wrapper; the keyed form is needed inside lists. |
| Why must hooks be called in the same order every render? | Rules of hooks | React matches hook state by call order. A hook inside a condition or loop shifts every slot after it. |
| What is the virtual DOM and is it why React is fast? | Common myth | It is the element tree React diffs. The benefit is a declarative model with reasonable updates, not raw speed over hand-written DOM code. |
Hooks and state questions
function Counter() {
const [count, setCount] = useState(0);
function handleClick() {
setCount(count + 1);
setCount(count + 1);
setCount(count + 1);
console.log(count);
}
return <button onClick={handleClick}>{count}</button>;
}Each call uses the count from this render, which is 0, so all three schedule "set to 1". The log prints 0 because state is a snapshot: the variable does not change until the next render. With the updater form, setCount((c) => c + 1) three times, each update builds on the previous one and the button shows 3.
- What is batching? Several state updates in one event are applied in a single render. Since React 18 with createRoot, updates inside timeouts, promises and native handlers are batched too.
- When do you use useReducer instead of useState? When the next state depends on the previous in several ways, or many fields change together, so the transitions live in one tested function.
- What is useRef for? A mutable box that survives renders without causing one: DOM nodes, timer ids, the latest value for a callback. Changing
ref.currentdoes not re-render. - How does context cause re-renders? Every component that reads a context re-renders when its value changes by reference. Creating a new object for the value on each provider render makes all consumers render each time.
- What makes a good custom hook? It extracts stateful logic with a clear name and return value, such as
useDebouncedValueoruseOnlineStatus, and follows the rules of hooks itself. - Why should state be immutable? React compares references to decide what changed. Mutating an array and setting the same reference can skip the update.
- Where should derived values live? Compute them during render from props and state. Copying them into state with an effect creates two sources of truth that drift.
useEffect questions
Effects get the most follow-up questions because they cause the most bugs. An effect synchronizes the component with something outside React, such as a subscription, a timer, a non-React widget or a network request. It runs after the commit, and its cleanup runs before the next run and on unmount.
function Timer() {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const id = setInterval(() => setSeconds(seconds + 1), 1000);
return () => clearInterval(id);
}, []);
return <p>{seconds}s</p>;
}
// Fix: setSeconds((s) => s + 1), so the closure no longer needs seconds.useEffect(() => {
let ignore = false;
fetchUser(userId).then((user) => {
if (!ignore) setUser(user);
});
return () => {
ignore = true;
};
}, [userId]);| Question | What it tests | What a strong answer shows |
|---|---|---|
| Why does my effect run twice on mount? | StrictMode | In development, StrictMode mounts, unmounts and remounts to surface missing cleanup. Production runs it once. The fix is correct cleanup, not removing StrictMode. |
| An effect depends on an object created in render and runs every time. Why? | Dependency identity | A new object each render is a new reference. Depend on primitive fields, move the object inside the effect, or memoize it. |
| useEffect or useLayoutEffect? | Timing | useLayoutEffect runs after DOM changes but before paint, for measuring layout and avoiding a flicker. Default to useEffect. |
| Do you need an effect to respond to a button click? | Event versus effect | No. Logic caused by a user action belongs in the event handler. Effects are for syncing with something because the component is on screen. |
| How would you fetch data in a production app? | Data fetching | A framework loader or a query library that handles caching, deduplication, retries and race conditions, rather than hand-written effects everywhere. |
Performance questions
- What does React.memo do? It skips re-rendering a component when its props are shallowly equal to last time. It only helps if the props are actually stable.
- useMemo versus useCallback? useMemo caches a computed value, useCallback caches a function. Both matter mainly when the result is passed to a memoized child or used as an effect dependency.
- Should you wrap everything in memo? No. Measure with the React DevTools Profiler first. Unneeded memoization adds comparison cost and makes code harder to read.
- How do you keep typing fast in a big filtered list? Keep the input state local, defer the expensive list with
useDeferredValueorstartTransition, and virtualize long lists. - How do you shrink the initial bundle? Route-level code splitting with
React.lazyand Suspense, removing heavy dependencies, and loading rarely used widgets on demand. - What causes a cascade of renders from context? One large context holding fast-changing values. Split contexts by update frequency or move fast state into a store with selectors.
Senior React and scenario questions
| Scenario | What it tests | What a strong answer shows |
|---|---|---|
| After deleting the second row, the third row's input shows the deleted row's text. | Keys | The list uses index keys. Use a stable id from the data. |
| The server-rendered page logs a hydration mismatch. | SSR and hydration | Render output differs between server and client: dates, random values, or reading window during render. Make the first client render match, then update in an effect. |
| One failing widget blanks the whole page. | Error boundaries | Wrap independent regions in error boundaries with a fallback. They catch render errors, not errors in event handlers or async code. |
| Where should server data, form state and UI state live? | State architecture | Server data in a cache layer, form state in the form, UI state as local as possible, and a global store only for truly shared client state. |
| What changes with Server Components? | Modern React | In frameworks that support them, components are server components by default: they run on the server, can read data directly and send no JavaScript of their own. Interactive parts opt in as client components with the "use client" directive, and they can use state and effects. |
| How do you test a component? | Testing | Render it with Testing Library, interact the way a user would (by role and label), and assert on what is visible. Mock the network at the boundary, not React internals. |
| A dashboard re-renders every widget every second. | Profiling | Profile, find the shared state or context that changes every tick, then isolate that state to the widget that needs it. |
Fictional example
- Our admin table had about two thousand rows and typing in the filter box lagged badly. The Profiler showed that every keystroke re-rendered every row, because the filter text lived in a context that also held the selected rows, and each row read that context for its checkbox. I moved the filter text into the toolbar's own state, passed only the debounced value to the table, split selection into its own context, and virtualized the rows so only the visible ones mounted. Typing became smooth and the Profiler showed a handful of rows rendering per change instead of all of them. The lesson I took was to profile before adding memo, because the cause was where state lived, not missing memoization.
React practice plan
- Week 1: rebuild five small components from memory: a counter with history, tabs, an accessible modal, a debounced search with loading and error states, and a form with validation. Narrate why each piece of state lives where it does.
- Week 2: write ten predict-the-render snippets about snapshots, updater functions, effects, cleanup and keys, then check them in a sandbox.
- Week 3 (senior): profile an app you own, write down one change you would make to its state architecture, and prepare a story about a production bug you traced to rendering or effects.
React sits on top of the language, so pair this page with JavaScript interview questions and, for typed codebases, TypeScript interview questions. The full frontend loop, including CSS and accessibility, is in frontend developer interview questions.
Building a component while talking is harder than either one alone. In a mock React round, Natively (an AI interview assistant for Mac and Windows) writes a transcript on your computer, so afterwards you can check whether you explained state placement or just typed. It can also read a component or prompt from a screenshot during practice and suggest an approach or code, and with Pro or the free trial it uses the résumé and job description you added. Past sessions stay in your history with their notes.
Questions people ask
What are the most common React interview questions?
What triggers a re-render, props versus state, why keys matter, how useState updates are batched, what useEffect is for and how its cleanup works, controlled inputs, and when memo, useMemo or useCallback help.
What do React developer interviews include besides questions?
Usually a live build in a sandbox, such as a searchable list, a form or a modal, plus a snippet where you predict what renders after a click. Senior rounds add state architecture and performance discussions.
Why does my useEffect run twice in development?
React StrictMode mounts, unmounts and mounts components again in development to expose effects without proper cleanup. It runs once in production.
How should I prepare for a senior React interview?
Be ready to explain where each kind of state should live, how you fetch and cache server data, how you profile and fix slow renders, and how you test components, using examples from your own work.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
