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 useMemo and useCallback, and when should you not use them?

    useMemo caches the result of a calculation, and useCallback caches a function itself, both until their dependencies change. Use them for expensive calculations or to keep values stable for memoized children or effect dependencies; skip them for cheap work, where they only add complexity.

    IntermediateIn-depth3 min read
  2. Why does useCallback often do nothing unless the child is wrapped in React.memo?

    useCallback keeps a function reference stable, but a child still re-renders whenever its parent does unless the child is wrapped in React.memo or the function is a hook dependency. The stable reference only helps where something compares it.

    IntermediateQuick answer1 min read