React Interview Questions: Code Splitting & Performance

Reviewed by Mark Dickie · Last updated

5 questions on this page you can answer and see marked on the spot. Go to the first one

React code splitting is the practice of breaking a bundle into smaller chunks that load on demand, so the browser only downloads what a route or component actually needs. For interviews, you should know the three main mechanisms: React.lazy with Suspense for component-level splitting, dynamic import() for route or feature chunks, and Suspense fallbacks that keep the UI usable while chunks load. You should also be able to explain why splitting reduces initial JavaScript payload, how it defers work on the main thread until a chunk is actually needed, and where it trades initial load time for later fetch latency.

What does a React interview test on code splitting?

Interviewers typically check whether you can identify the right boundary to split at, explain the cost model, and avoid common mistakes like splitting too granularly or forgetting the fallback UI. Expect questions that ask you to compare approaches and justify trade-offs.

MechanismWhat it splitsTypical boundaryKey API
React.lazy + SuspenseA single component's chunkRoute-level or modal-levellazy(() => import('./Page'))
Dynamic import()Any module or feature chunkFeature, route, or heavy dependencyimport('./chart-lib') in a handler
Route-based splitting (framework)Entire route treesTop-level routenext/dynamic, loadable-components, router loaders

How should you prepare for code-splitting questions?

  1. Learn when to split: measure first with the Coverage tab in Chrome DevTools and Lighthouse, then split the largest unused-bytes on initial load.
  2. Practice the Suspense API: wrap lazy components in <Suspense fallback={...}> and understand what happens when a chunk fetch fails.
  3. Understand waterfall fetching: nested Suspense boundaries can hide the cost of sequential chunk downloads, so know when to use a single boundary versus several.
  4. Know the gotchas: server-side rendering needs special handling (React.lazy is client-only), and overly fine-grained splits add request overhead that can outweigh the savings.
  5. Review the React docs on lazy, Suspense, and the use hook (available in React 19), which changes how you can read promises inside components.

Key facts

  • Tarmac has 11 React interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 1,185 job postings asking for React in November 2026.
  • Roles asking for React advertise a median base salary of £75,000, across 477 job postings as of November 2026.
  • Tarmac last reviewed these React interview questions on 3 December 2026.

At a glance

Questions10 shown · 11 in the bank
Difficulty1–5 of 5
FormatsOrdering, Multiple answer, Multiple choice, True / false, Code output, Find the bug, Short answer, Fill in the blank, Coding exercise
Interactive1 run your code against tests, in the app

What you'll review

  1. code splitting

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

A component is defined as const Chart = React.lazy(() => import('./Chart')) and rendered inside <Suspense fallback={<Spinner />}>. Order what happens the first time <Chart /> renders.#

Put these in order

Show answer

When a React.lazy component first renders, React calls the import() factory first. The component then suspends, and the nearest <Suspense> shows its fallback. Next, the browser downloads the separate code chunk. Finally, the import promise resolves and React re-renders, replacing the fallback with the real component. Each step depends on the previous one, so the order is fixed.

Why:

On the first render, React runs the lazy factory, which starts the dynamic import() and returns a pending promise. Because the module isn't loaded yet, the component suspends and the closest Suspense boundary shows its fallback. The fallback stays on screen while the browser downloads the split chunk. When the download finishes, the promise resolves with the module's default export. React then retries the render and replaces the spinner with the real Chart. Each step depends on the one before it, so only one order works.

Which of the following statements about code splitting in a React app built with a modern bundler (webpack, Vite, or Rollup) are true? Select all that apply.#

Options

Pick every one that applies.

Show answer

In React, code splitting uses dynamic import() calls, which bundlers turn into separate chunks that load on demand. This makes the initial bundle smaller and the first load faster. Splitting by route is a common place to start. Static top-level imports don't create on-demand chunks, and code splitting doesn't reduce the app's total JavaScript. It only delays loading parts of it.

Why:

A dynamic import() returns a promise, and bundlers use it as a split point to put that module in a separate chunk that is fetched only when needed. Because of this, the initial bundle gets smaller, which can make the first load faster. Routes are a natural place to split because a user usually visits one page at a time. A static top-level import puts the module into the importing chunk, so it is not loaded on demand. Code splitting also doesn't remove any code. It only spreads the same code across more files that load later, so the total amount of JavaScript stays about the same or grows a little because of chunk overhead.

In a React app bundled with a modern bundler (webpack, Vite, or Rollup), which JavaScript syntax tells the bundler to put a module into its own separately loaded chunk?#

Options

Show answer

The dynamic import('./module') expression is the code-splitting point for webpack, Vite, and Rollup. It returns a Promise, and the bundler puts the imported module in a separate chunk that is fetched on demand. React.lazy relies on this syntax. Static imports and synchronous require calls keep the module in the same bundle.

Why:

Modern bundlers use the dynamic import('./module') expression, which returns a Promise, as the split point. The bundler emits that module as a separate chunk and fetches it only when the call runs. A static top-level import puts the module in the importing chunk. A synchronous require call still gets bundled inline. export default only controls what a module exports and has nothing to do with chunking.

In React 18, if ./Charts.js exports a component only as a named export (export function BarChart() {...}) and has no default export, const BarChart = React.lazy(() => import('./Charts')) will correctly render BarChart.#

Options

Show answer

False. React.lazy only works with a module's default export. The loader's Promise must resolve to an object whose default property is a component. If the module only has a named export, map it yourself: lazy(() => import('./Charts').then(m => ({ default: m.BarChart }))). You can also re-export the component as default from another module.

Why:

React.lazy expects its loader function to return a Promise that resolves to a module object whose default property is a React component. When the module only has a named export, module.default is undefined and React throws an error when it tries to render the lazy component. The usual fix is to map the named export onto default: React.lazy(() => import('./Charts').then(m => ({ default: m.BarChart }))). Another fix is to add an intermediate module that re-exports BarChart as its default export.

Using React 18 with createRoot (no StrictMode), what gets logged to the console in total, from the first render until Chart.js finishes loading and shows up? Give one log per line, in order.#

// Chart.js
export default function Chart() {
  console.log('Chart');
  return <div>chart</div>;
}

// App.js
import { lazy, Suspense } from 'react';
const Chart = lazy(() => import('./Chart'));

function Spinner() {
  console.log('Spinner');
  return <p>Loading...</p>;
}

export default function App() {
  console.log('App');
  return (
    <Suspense fallback={<Spinner />}>
      <Chart />
    </Suspense>
  );
}
Show answer
App
Spinner
Chart
Why:

App renders first and logs App. When React tries to render the lazy Chart, its chunk isn't loaded yet, so it suspends. The nearest <Suspense> boundary then renders its fallback, and Spinner logs Spinner. When the dynamic import() resolves, React re-renders only the content inside the Suspense boundary, so Chart renders and logs Chart. App does not render again because its state and props never changed. Since StrictMode is off, nothing is logged twice.

How do React.lazy and <Suspense> work together for code splitting?#

Options

Show answer

React.lazy defers loading a component's code until it actually renders, and <Suspense fallback={…}> shows the fallback while that chunk downloads. Calling React.lazy(() => import('./X')) returns a component whose bundle is fetched on first render; until the dynamic import resolves, the nearest Suspense boundary displays its fallback. A lazy component must be rendered inside such a boundary.

Why:

React.lazy(() => import('./X')) creates a component whose code is fetched on first render; while that dynamic import is pending the nearest <Suspense> boundary renders its fallback. A lazy component must be rendered inside a Suspense boundary.

Each time the user clicks Toggle, this component briefly shows the "Loading…" fallback again, and any internal state inside Chart (zoom level, for example) is reset, even though ./Chart was already downloaded. Which line causes this?#

import { lazy, Suspense, useState } from 'react';

export default function Dashboard() {
  const [tab, setTab] = useState('overview');
  const Chart = lazy(() => import('./Chart'));

  return (
    <div>
      <button onClick={() => setTab(tab === 'overview' ? 'details' : 'overview')}>Toggle</button>
      <Suspense fallback={<p>Loading…</p>}>
        <Chart mode={tab} />
      </Suspense>
    </div>
  );
}
Show answer

The bug is on line 5.

Why:

Line 5 calls lazy() inside the component body, so every render of Dashboard creates a brand-new lazy component type. React compares element types by reference. When the type changes, React unmounts the old Chart subtree and mounts a fresh one, which throws away its state. The new lazy wrapper hasn't resolved yet, so it suspends and shows the fallback again, even though the bundler has already cached the module. The fix is to move const Chart = lazy(() => import('./Chart')); to module scope, outside Dashboard, so the component type stays the same across renders.

In a React 18 app, a component does this:#

Show answer

React.lazy is called inside the render body, so every render makes a brand-new lazy component with a different identity. React compares element types by reference. A new type means it unmounts the old subtree and mounts a fresh one, so internal state is lost. The new lazy wrapper also has no resolved status cached yet, so it suspends again and the fallback shows. The bundler caches the module, so it isn't downloaded again, but the lazy wrapper still has to resolve once more. To fix it, declare lazy components at module scope, once per module. For a dynamic key, build a map at module level, e.g. const charts = { bar: lazy(() => import('./charts/bar.js')), ... }, and pick charts[kind]. You could also memoize or cache the lazy component per key outside render. A memo at the component level is weaker because it is not guaranteed to persist. Using explicit import paths also lets the bundler create proper chunks. Optionally, preload on hover, or use startTransition so a kind change keeps the old UI on screen instead of showing the fallback.

Why:

React reconciles by element type identity. Calling lazy() during render returns a new component type on every render, which forces a remount, so state is lost, and starts a new suspension, so the fallback appears. Each lazy component's identity has to stay stable, which means creating it at module scope, for example in a map keyed by chart kind, or caching it per key outside the render path.

In React 18, a lazy component is already mounted and showing content. A state update then makes it render a different lazy component that hasn't loaded yet. Normally the nearest <Suspense> boundary would swap the visible content for its fallback. To keep showing the old UI while the new chunk downloads, mark the update as non-urgent by wrapping the state setter in _____ (the hook form, useTransition, returns a start function you can use the same way). Separately, a lazy component that suspends during an urgent (non-transition) update with no <Suspense> ancestor anywhere makes React throw an error, which the nearest error _____ would catch. And if the dynamic import() promise rejects, for example from a network failure, the error is rethrown during render and caught by that same kind of component, not by <Suspense>.#

Show answer

In React 18, a lazy component is already mounted and showing content. A state update then makes it render a different lazy component that hasn't loaded yet. Normally the nearest <Suspense> boundary would swap the visible content for its fallback. To keep showing the old UI while the new chunk downloads, mark the update as non-urgent by wrapping the state setter in **startTransition** (the hook form, useTransition, returns a start function you can use the same way). Separately, a lazy component that suspends during an urgent (non-transition) update with no <Suspense> ancestor anywhere makes React throw an error, which the nearest error boundary would catch. And if the dynamic import() promise rejects, for example from a network failure, the error is rethrown during render and caught by that same kind of component, not by <Suspense>.

Why:

In React 18, wrapping an update in startTransition (or the start function returned by useTransition) marks it as a transition. If that transition makes already-visible content suspend, React keeps the current UI on screen instead of switching to the Suspense fallback, which avoids a jarring loading flash when switching tabs or routes. An urgent update that suspends with no Suspense ancestor anywhere in the tree causes React to throw, and that error is caught by the nearest error boundary, a class component that defines getDerivedStateFromError or componentDidCatch. A rejected import() is likewise treated as a render error, so it also propagates to the nearest error boundary rather than to <Suspense>, which only handles the pending state of a lazy component. That is why lazy-loaded routes are often wrapped in an error boundary that offers a retry.

React.lazy(factory) wraps a lazy payload in a small state machine: uninitialized → pending → resolved | rejected. Write simulateLazy(events), a synchronous simulation of that payload with no React involved.#

Starter code

function simulateLazy(events) {
  // TODO: model uninitialized/pending/resolved/rejected
  return { reads: [], factoryCalls: 0 };
}

Your solution must pass

  • basic resolve and cache
  • settle before first read ignored

This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See react salaries and hiring demand from live job postings.

The other 1 question

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 1 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.