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
- 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.
- Profiler tab: record interactions, see why components re-rendered.
- 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.
- Sources: breakpoints, conditional breakpoints,
- Error overlays in Vite and Next.js show source-mapped errors and hydration diffs.
- Logging:
console.logwith labels,console.tablefor arrays;useDebugValuefor custom hooks. - 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";23export function useCart() {4 const [items, setItems] = useState<{ id: string; qty: number }[]>([]);5 useDebugValue(`${items.length} items`); // shows next to the hook in React DevTools6 return { items, setItems };7}89export function CheckoutButton() {10 const { items } = useCart();1112 useEffect(() => {13 console.table(items); // readable logging of arrays of objects14 }, [items]);1516 function checkout() {17 if (items.length === 0) {18 debugger; // pauses here when DevTools is open19 }20 console.log("%ccheckout", "color: white; background: purple; padding: 2px 6px", items);21 }2223 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.