EasyReact Fundamentals📖 Theory Question

What is the difference between state and props?

💡

Hint

Props = external inputs (immutable); state = internal memory (mutable via setState)

Full Answer

  • Props — passed in from outside, owned by the parent, read-only inside the component
  • State — owned and managed by the component itself, mutable via setState/useState, triggers re-render when changed
function Counter({ initialCount, step = 1 }) {
  //              ↑ props — given from parent, read-only here

  const [count, setCount] = useState(initialCount);
  //     ↑ state — owned by this component

  return (
    
  );
}

When state changes: React re-renders the component and all its children.

When props change: the parent re-renders, passing new props, which causes the child to re-render.

💡 A common mistake: trying to sync state with props using useEffect. Instead, derive values during render if possible. If a prop controls the initial value, use it only in useState's initializer — not as a useEffect dep.

More React Fundamentals Questions

EasyWhat is React and what problem does it solve?EasyWhat is JSX and how does it work under the hood?EasyWhat is the Virtual DOM and how does reconciliation work?EasyWhat is the difference between a controlled and uncontrolled component?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint