ReactEasy

How to debug a React app?

Debug React apps with React DevTools (inspect the component tree, props, state and hooks, and profile renders), browser DevTools (breakpoints, debugger, network, console, performance), the error messages and component stacks React prints, and framework error overlays. Reproduce the bug in a small case, form a hypothesis, and verify with breakpoints rather than guesswork.

Tools

  1. React DevTools (Components tab): select an element, inspect and edit props, state, hooks and context; see which component rendered it ("rendered by"); toggle Suspense and error boundaries.
  2. Profiler tab: record interactions, see why components re-rendered.
  3. Browser DevTools:
    • Sources: breakpoints, conditional breakpoints, debugger; statements, step through code with source maps.
    • Network: failed requests, payloads, CORS errors, slow APIs.
    • Console: React's warnings include component stacks.
    • Performance panel: React's Scheduler and Components tracks (React 19.2) show what React was doing.
  4. Error overlays in Vite and Next.js show source-mapped errors and hydration diffs.
  5. Logging: console.log with labels, console.table for arrays; useDebugValue for custom hooks.
  6. Testing: write a failing test that reproduces the bug, then fix it.

Common React bug categories and where to look

  • Stale values: dependency arrays and closures.
  • Infinite loops: effects setting their own dependencies ("Maximum update depth exceeded").
  • Wrong item state in lists: keys.
  • Hydration errors: server versus client differences.
  • Effects running twice in development: Strict Mode, needs cleanup.

AI and MCP tooling

Framework dev servers (for example Next.js 16's /_next/mcp) can expose errors and routes to coding agents.

Code example

tsx
1import { useDebugValue, useEffect, useState } from "react";
2
3export function useCart() {
4 const [items, setItems] = useState<{ id: string; qty: number }[]>([]);
5 useDebugValue(`${items.length} items`); // shows next to the hook in React DevTools
6 return { items, setItems };
7}
8
9export function CheckoutButton() {
10 const { items } = useCart();
11
12 useEffect(() => {
13 console.table(items); // readable logging of arrays of objects
14 }, [items]);
15
16 function checkout() {
17 if (items.length === 0) {
18 debugger; // pauses here when DevTools is open
19 }
20 console.log("%ccheckout", "color: white; background: purple; padding: 2px 6px", items);
21 }
22
23 return <button onClick={checkout}>Checkout</button>;
24}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.

Open in study app