Frontend interview practice question

Why does my component re-render when its props didn't change?

HighIntermediateReact

Interview quick answer

Trace a React re-render to its real trigger: a parent render, prop identity that changed even though values look equal, a context provider value recreated inline, or a remount caused by key, type, or position. Covers render vs commit, bailouts, a profiling-first workflow, and when memoization makes things worse.

Interview focus

This React interview question tests whether you can explain React Re-renders Without Prop Changes: Fixes, connect it to production trade-offs, and handle common follow-up questions.

  • React Re-renders Without Prop Changes: Fixes explanation without falling back to memorized definitions
  • Rendering and State reasoning, edge cases, and production failure modes
  • How you would answer the most likely React interview follow-up
Practice more React interview questions
Interview answer drill

Use this React interview question to rehearse a quick answer, common mistake, follow-up, and production pitfall.

Full interview answer

The bug to explain

The props did not change, yet the child rendered again. Three explanations cover almost every case: the parent rendered and children render by default unless a React.memo boundary bails out; the props changed by identity even though they look equal, because an inline object or callback is a new reference every render; or a context provider value was recreated and every consumer re-ran. A fourth case looks like a re-render but is a remount: the key, type, or position changed and local state was thrown away. The sections below show how React decides, how to tell these apart in the Profiler, and which fix is smallest.

Core idea

React re-renders a component when it thinks that component’s inputs might have changed (state/props/context). A re-render means: “run the component again to produce a new element tree.” It does not necessarily mean the browser DOM will change.

Trigger

What changed?

What React does

Notes / common gotcha

State update

setState / setX / dispatch

Schedules a render for that component

useState bails out if the new state is Object.is-equal to the old state; new object/array references always count as “changed”.

New props

Parent renders and passes props down

Child is rendered by default

Even if props are “equal by value”, React still re-renders unless the child is memoized (React.memo/PureComponent).

Context update

A Context.Provider value changes

All consuming components re-render

Context is identity-based: {...} created inline will change every render unless memoized.

Force update

forceUpdate() (class) or “dummy state”

Forces a render

Usually a code smell; prefer state/props-driven rendering.

The main reasons React decides to re-render a component

What happens during a re-render

React runs the component (function body or class render()) to build a new React element tree. Then it reconciles (diffs) it against the previous tree. Only the differences are committed to the DOM.

Phase

What runs here

What must be true

Render phase

Component function body / class render()

Must be pure: no side effects (no data fetching, subscriptions, DOM writes).

Commit phase

DOM mutations + layout effects

Safe place for effects: useEffect, useLayoutEffect, lifecycle methods.

Render vs commit (why render() must be pure)
JSX
function Counter() {
  const [count, setCount] = React.useState(0);

  // This function body is the “render” for function components.
  // It runs again when state/props/context changes.
  return (
    <button onClick={() => setCount((c) => c + 1)}>
      Count: {count}
    </button>
  );
}
                  

So what is render() doing?

render() does not “trigger” updates. It’s the function React calls after an update is scheduled, to compute the next UI description. For function components, the component function itself plays the same role as render().

JSX
class Profile extends React.Component {
  render() {
    // Called during the render phase to compute UI.
    return <h1>{this.props.name}</h1>;
  }
}
                  

Worked example: parent re-renders, child logs, DOM barely changes

Imagine a search page where typing updates local input state in the parent. React may re-run the child result pane too, especially if you pass inline callbacks or config objects. That still does not prove the browser rewrote the whole subtree. It only proves React re-computed the next UI and then decided what, if anything, must be committed.

JSX
const SearchResults = React.memo(function SearchResults({ items, onSelect }) {
  console.log('SearchResults render');
  return items.map((item) => (
    <button key={item.id} onClick={() => onSelect(item.id)}>{item.label}</button>
  ));
});

function SearchPage({ allItems }) {
  const [query, setQuery] = React.useState('');
  const visible = allItems.filter((item) => item.label.includes(query));

  return (
    <>
      <input value={query} onChange={(e) => setQuery(e.target.value)} />
      <SearchResults
        items={visible}
        onSelect={(id) => console.log('select', id)}
      />
    </>
  );
}
                  

In that example, the inline onSelect function creates a new reference on every parent render, so React.memo cannot bail out even if the visible list did not change. The browser may only update the text input, but React still had to re-run SearchResults first.

Another production bug: context churn

Parent state is not the only rerender trigger. A provider value created inline can re-run every consumer even when the field they care about did not change.

JSX
const SearchContext = React.createContext(null);

function SearchShell() {
  const [theme, setTheme] = React.useState('dark');
  const [query, setQuery] = React.useState('');

  // ❌ New object identity every render
  const value = { query, setQuery };

  return (
    <SearchContext.Provider value={value}>
      <button onClick={() => setTheme((t) => t === 'dark' ? 'light' : 'dark')}>
        Toggle theme
      </button>
      <SearchBox />
    </SearchContext.Provider>
  );
}

// Even theme-only renders recreate value, so consumers can rerender too.
                  

Skipping re-renders (bailouts)

By default, parent re-renders propagate to children. To skip work, React needs an explicit bailout rule.

Technique

How it skips work

When to use

React.memo(Component)

Shallow-compares props; if equal, skips re-render

Pure presentational children with stable props

PureComponent / shouldComponentUpdate

Controls whether class component re-renders

Legacy/class codebases

Stable references

Avoid changing prop identity unnecessarily

Use useCallback/useMemo only when it prevents real re-renders

Common ways to prevent unnecessary re-renders

Event

What React means by it

What happens to local state

Initial mount

Component appears in the tree for the first time

Fresh state is created.

Re-render

React re-runs the component because inputs might have changed

Existing local state is preserved.

Remount

React treats it as a different component because key/type/position changed

Local state resets.

No-op commit

React rendered, diffed, and found nothing DOM-visible to change

State stays the same; the browser may not visibly update.

The follow-up distinction interviewers often want next

Before/after bug: memoized child still hot because prop identity changes

The usual production surprise is: “But the child is memoized.” If you keep allocating new objects/functions in the parent, the memo boundary sees changed props every time.

JSX
const Chart = React.memo(function Chart({ filters, onPointClick }) {
  console.log('Chart rendered');
  return <canvas />;
});

function Dashboard({ region }) {
  // ❌ New references every render
  return (
    <Chart
      filters={{ region, includeArchived: false }}
      onPointClick={(id) => console.log(id)}
    />
  );
}

function DashboardFixed({ region }) {
  const filters = React.useMemo(() => ({ region, includeArchived: false }), [region]);
  const onPointClick = React.useCallback((id) => console.log(id), []);
  return <Chart filters={filters} onPointClick={onPointClick} />;
}
                  

Common misconception

Correct framing

“React re-renders the whole app.”

React schedules work for the affected part of the tree. But parent renders do propagate unless you add bailout boundaries (memo) and keep identities stable.

“Virtual DOM diff always computes the minimal edit.”

Reconciliation is heuristic and optimized for common UI patterns. With good keys/types, it’s very efficient; with bad keys/identity churn, it can do extra work.

“If a component re-rendered, the DOM changed.”

Not necessarily. If the computed output is the same (or the changed parts don’t affect the DOM), commit can be a no-op.

“useCallback/useMemo always improves performance.”

They help only when they prevent real work (rerenders of expensive children, expensive computations). Overuse adds complexity and overhead.

Interview-grade corrections to typical statements

Profiling-first workflow

The goal is not to stop every rerender. The goal is to debug the expensive ones first. Start with React DevTools Profiler or “Why did this render?” before you optimize, then ask three questions in order: which component is actually hot, which prop, context, or state change triggered it, and can you reduce the blast radius without adding a maze of memoization?

Optimization lever

What it actually reduces

Best use

Colocate state (move it down)

The number of components affected by updates

Keep state as close as possible to where it’s used, so fewer parents re-render.

Split components

The size of the rerendered subtree

Separate “fast-changing” parts from “mostly-static” parts.

React.memo / PureComponent

Re-rendering of child components

Pure/presentational children with stable props.

Stable prop identities

False-positive “prop changed” signals

Avoid inline objects/functions when they’re passed to memoized children.

Memoize Context value

Broad consumer rerenders

Wrap provider value creation in useMemo to avoid rerendering all consumers.

Practical ways to reduce unnecessary re-renders (in the order that usually matters most)

When memoization hurts

Memoization is a pitfall when you add it before profiling. Dependency arrays become harder to reason about, stale closures sneak in, and shallow comparison work can outweigh the rerender you were trying to save. Use memo tools when they remove a measured bottleneck, not as a blanket rule. If the real issue is that an update is legitimately expensive or low-priority, useTransition() and useDeferredValue() keep the input responsive while heavier results lag slightly behind.

JSX
const Row = React.memo(function Row({ item, onSelect }) {
  return <button onClick={() => onSelect(item.id)}>{item.label}</button>;
});

function List({ items }) {
  return items.map((item) => (
    <Row
      key={item.id}
      item={item}
      onSelect={(id) => console.log(id)} // ❌ new function every render
    />
  ));
}

function ListFixed({ items }) {
  const onSelect = useCallback((id) => console.log(id), []);
  return items.map((item) => <Row key={item.id} item={item} onSelect={onSelect} />);
}
                  

Broad context blast radius

A memoized child still re-renders if it reads from a context whose value changes every keypress. This is why context splitting often beats adding more memo wrappers.

JSX
const SearchContext = React.createContext(null);

function App() {
  const [theme, setTheme] = useState('light');
  const [searchTerm, setSearchTerm] = useState('');

  // ❌ Theme-only consumers still rerender on every keystroke
  const value = useMemo(() => ({ theme, searchTerm, setSearchTerm }), [theme, searchTerm]);
  return <SearchContext.Provider value={value}><Layout /></SearchContext.Provider>;
}

// Better: split fast-changing search state from slower theme state.
                  

Remount, not rerender: keys and wrappers

Changing a component’s key or swapping wrappers (for example Fragment to div) causes a remount with fresh local state, not a re-render. Double render logs under StrictMode in development are a separate signal, not production behavior.

JSX
function Editor({ userId }) {
  const [draft, setDraft] = React.useState('');
  return <input value={draft} onChange={(e) => setDraft(e.target.value)} />;
}

// ❌ Re-render keeps local state, but changing key remounts and wipes it
<Editor userId={activeUserId} key={activeUserId} />
                  

One-line distinction

Rerender means React ran the component again, remount means React threw away the old identity and local state, and commit means React actually mutated the DOM. Those are related, but they are not the same event.

Summary

React re-renders when state/props/context might have changed. A “render” means recomputing the next React element tree, not necessarily updating the DOM. The class render() method (or function component body) is the pure computation React runs during the render phase; DOM updates happen later in the commit phase.

Guides
Preparing for interviews?

Built in public

The code behind FrontendAtlas lives on GitHub. A star helps other frontend engineers find it.

Star on GitHub