Interview Q&A / React

INTERVIEW Q&A · 58 QUESTIONS

React interview questions

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

  1. When would you choose useReducer over useState?

    Choose useReducer when state has several related fields, or the next state depends on complex rules and actions. It centralises update logic in one pure function, which is easier to test and reason about than many scattered setters.

    IntermediateQuick answer1 min read
  2. Why must a reducer function be pure, and what breaks if it is not?

    React may call a reducer more than once with the same inputs, for example in Strict Mode. A pure reducer returns a new state from state and action only. Mutating state or running side effects inside it gives wrong or duplicated results.

    IntermediateQuick answer1 min read