LearnThatStack Ace your next interview
React · question
Question 12 of 103

What's the difference between props and state?

beginner
← All React questions
Re-explain

Props are inputs a component receives from its parent, and state is data a component owns and changes itself. Props flow down and are read-only, while state is the component's own memory.

Props State
Read-only Mutable
Passed from parent Local to component
Cannot be changed by component Can be changed by component
External data Internal data
Functional parameters Component memory

A component can't change its own props. When the parent passes new props, the component re-renders with them. State changes through the component's setter, like setCount, and each change also triggers a re-render. The two often meet, because a parent's state becomes a child's props.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for React One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • What goes wrong if you change a state object directly instead of calling the setter? React compares the old and new value by reference, so an in-place change can skip the re-render. Build a new object or array and pass that to the setter.
  • If props are read-only, how does a child tell its parent that something changed? The parent passes a function as a prop, the child calls it, and the parent updates its own state, which flows back down as new props.
  • Two sibling components need the same data. Where should that state live? In their closest common parent, passed down to both as props. Name the cost: more props to pass down, and each change re-renders that parent's subtree.
  • Is it a good idea to copy a prop into state with useState(props.value)? The copy only takes the first value, so later prop changes are ignored. A strong answer says compute from the prop during render, or reset with a key.
  • Right after calling setCount(count + 1), what does logging count print, and why? It still prints the old value. State is a snapshot per render; use the updater form setCount(c => c + 1) when the next value depends on the last.

What you can say

  1. Props are the inputs a component gets from its parent, and state is data the component owns and changes itself.
  2. Props flow down and are read-only. A component can't change its own props, and when the parent passes new ones, it re-renders with them.
  3. State is the component's own memory. It changes through its setter, like setCount, and each change also triggers a re-render.
  4. The two often meet, because a parent's state often becomes a child's props, like a count the parent owns and passes down for a child to display.
  5. The limit is that a child can never edit what it receives, so when I design a component I first ask who owns each piece of data, because only the owner can change it.

Weak answers to avoid

  • Says state is mutable, so you just change it Changing a state object in place can skip the re-render. Say state changes only through its setter, with a new value each time.
  • Treats props and state as unrelated They connect all the time, since a parent's state often becomes a child's props. Show that flow, or the answer sounds like a memorized table.
  • Copies props into state by default useState only reads its initial value once, so the copy goes stale when the parent sends new props. Read the prop directly instead.
  • Recites the table with no example A list of adjectives doesn't show understanding. Walk one case, like a count in the parent passed down, and say what re-renders when it changes.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the React cheatsheet.

← Back to all React questions
Pro · $10/mo

88 of 103 React answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime