Interview Q&A / React

INTERVIEW Q&A · 58 QUESTIONS

React interview questions

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

  1. What are the rules of hooks, and why do they exist?

    Call hooks only at the top level of a component or custom hook, never inside loops, conditions or nested functions, and only from React functions. React tracks hooks by call order, so the order must be the same every render.

    BeginnerQuick answer1 min read
  2. What is a custom hook, and why would you write one?

    A custom hook is a function whose name starts with use and that calls other hooks. It lets you reuse stateful logic across components. Each component that calls it gets its own separate state.

    BeginnerQuick answer1 min read
  3. What is the difference between function components and class components, and which should you use today?

    Function components are plain functions that use hooks for state and lifecycle behaviour. Class components use this.state and lifecycle methods. New code should use function components; classes still work, and error boundaries still need a class.

    BeginnerQuick answer1 min read