react-hooks/error-boundaries
eslint-plugin-react-hooks
import reactHooks from "eslint-plugin-react-hooks";
export default [
{
plugins: { "react-hooks": reactHooks },
rules: {
"react-hooks/error-boundaries": "error",
},
},
];Validates usage of error boundaries instead of try/catch for errors in child components
function Parent() {
try {
return <ChildComponent />; // If this throws, catch won't help
} catch (error) {
return <div>Error occurred</div>;
}
}function Component({promise}) {
try {
const data = use(promise); // Won't catch - `use` suspends, not throws
return <div>{data}</div>;
} catch (error) {
return <div>Failed to load</div>; // Unreachable
}
}function Parent() {
return (
<ErrorBoundary>
<ChildComponent />
</ErrorBoundary>
);
}function App() {
return (
<ErrorBoundary fallback={<div>Failed to load</div>}>
<Suspense fallback={<div>Loading...</div>}>
<DataComponent promise={fetchData()} />
</Suspense>
</ErrorBoundary>
);
}Examples from the ESLint documentation.
react-hooks/error-boundaries
eslint-plugin-react-hooks
import reactHooks from "eslint-plugin-react-hooks";
export default [
{
plugins: { "react-hooks": reactHooks },
rules: {
"react-hooks/error-boundaries": "error",
},
},
];react/error-boundaries
react plugin · correctness
{
"plugins": [
"react"
],
"rules": {
"react/error-boundaries": "error"
}
}Biome does not have this rule.
Validates against assignment/mutation of globals during render, part of ensuring that side effects must render outside of render
Validates against mutating props, state, and other values that are immutable
Validates against usage of libraries which are incompatible with memoization (manual or automatic)
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
Validates that components/hooks are pure by checking that they do not call known-impure functions
Validates correct usage of refs, not reading/writing during render. See the "pitfalls" section in useRef() usage