React Component API — React Technical Interview Questions & Answers

React Component API

React Component API

  • Component API means the methods React gives a class: setState, forceUpdate, render. setState merges object state (shallow) and schedules render. forceUpdate re-renders without changing state — almost never needed; it’s a smell.
  • Hooks world: useState / useReducer replace setState. There is no forceUpdate. If a fresher recites forceUpdate as daily API, steer them back to ‘fix the state, don’t force paint’.
  • React Component API — output: class vs hooks. Interview: name setState, then say we use useState now.
  Parent
    │ props (read-only)
    ▼
  Child → UI

Technical Interview Tip: setState vs useState. Avoid forceUpdate.

Code Examples for React Component API

Example

// Component API
console.log("class : this.setState / this.forceUpdate");
console.log("hooks : useState / useReducer");
console.log("don't : call setState in render forever");

React Component API — output: class vs hooks. Interview: name setState, then say we use useState now.

How to Explain React Component API to an Interviewer

Explain React Component API as if you are teaching a junior — definition, then one tiny UI.

setState, render, rare forceUpdate. Hooks : useState / useReducer.

What does the example show on screen (or print), and what does that prove?

React Component API — output: class vs hooks

What mistake do freshers make with React Component API?

setState, render, rare forceUpdate.