Interview Q&A / React

INTERVIEW Q&A · 58 QUESTIONS

React interview questions

Rendering, state, hooks, keys and effects, explained with small examples.

  1. What is the difference between state and props in React?

    Props are inputs passed into a component by its parent and are read-only inside it. State is data a component owns and can change over time, and changing it makes the component re-render.

    BeginnerIn-depth3 min read
  2. Can a child component modify the props it receives?

    No. Props are read-only; React treats them as immutable snapshots from the parent. To change a value, the parent passes down a callback, and the child calls it so the parent updates its own state.

    BeginnerQuick answer1 min read
  3. How do you give a prop a default value in a modern function component?

    Use default values in the destructured parameters, such as function Badge({ color = 'blue' }). The default applies only when the prop is undefined, not when it is null or an empty string.

    BeginnerQuick answer1 min read
  4. What is the children prop in React, and when is it useful?

    children is the content placed between a component's opening and closing tags. It lets a component wrap whatever the caller supplies, which is how layouts, cards and modals stay reusable.

    BeginnerQuick answer1 min read
  5. Why is copying a prop into state usually a bug?

    The initial value is read once, on the first render. Later prop changes are ignored, so the component shows stale data. Use the prop directly, derive the value during render, or reset state with a key.

    IntermediateQuick answer1 min read