New
Introducing React Doctor for Enterprise

react-hooks-js/error-boundaries

Validates usage of error boundaries instead of try/catch for errors in child components

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Fires when a try/catch wraps a child component render (try { return <Child /> }) or wraps a use(promise) call — render errors and Suspense thenables bubble through the catch block invisibly, so neither pattern actually handles failure. False positive: try/catch around imperative work inside an event handler, useEffect body, or async helper — not around the JSX return statement itself.

Fix prompt

Use this once validation confirms the diagnostic is real.

For render errors, wrap the subtree in a real React error boundary — react-error-boundary's <ErrorBoundary fallback={...}> or your own class with componentDidCatch + getDerivedStateFromError. Pair it with <Suspense> around use(promise) so loading (Suspense) and error (boundary) states each have a fallback. See https://react.dev/reference/eslint-plugin-react-hooks/lints/error-boundaries

More React Compiler rules from the rules reference:

  • react-hooks-js/globals: Validates against assignment/mutation of globals during render, part of ensuring that [side effects must render outside of render](https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)
  • react-hooks-js/hooks: Validates the rules of hooks
  • react-hooks-js/immutability: Validates against mutating props, state, and other values that [are immutable](https://react.dev/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable)
  • react-hooks-js/incompatible-library: Validates against usage of libraries which are incompatible with memoization (manual or automatic)
  • react-hooks-js/preserve-manual-memoization: Validates that existing manual memoized is preserved by the compiler. React Compiler will only compile components and hooks if its inference [matches or exceeds the existing manual memoization](https://react.dev/learn/react-compiler/introduction#what-should-i-do-about-usememo-usecallback-and-reactmemo)