Capítulo 46 de 116

Chapter 46: ESLint Plugin React Hooks — Setup & Configuration

Core Idea

eslint-plugin-react-hooks is the official lint plugin that mechanically enforces the Rules of Hooks (Ch 116) and — in its newer releases — the broader Rules of React that React Compiler also relies on; installing and configuring it is what turns those rules from "something to remember" into "something the editor/CI catches."

Key Concepts

  • What the plugin covers: two rule families — the original Hooks-call-order/conditional-Hooks checks, and a newer, broader set of Rules-of-React checks (purity, immutability, effect timing) shared with what React Compiler itself needs to verify before it can safely optimize code.
  • config: the plugin ships presets (e.g. a recommended config) that bundle a sensible default rule set — most projects extend a preset rather than hand-picking every rule.
  • gating: a rule/setting related to runtime feature-flag gating, mirroring the React Compiler's own gating mechanism (Ch 44) so lint checks and compiler behavior can stay aligned when a codebase is rolling out compiler adoption behind a flag.
  • globals: configuration for recognizing project-specific global identifiers so the plugin doesn't misflag legitimate non-reactive globals as violations.
  • Recommended baseline: enable the plugin's recommended preset in every React project's ESLint config, and treat its errors as blocking — Ch 8 (Editor Setup) already calls this "not optional."

Key Takeaways

  1. Extend the plugin's recommended preset rather than assembling rules individually, unless you have a specific reason to diverge.
  2. The plugin's rule set has grown beyond "just Hook call order" — modern versions check the same Rules-of-React that React Compiler depends on.
  3. gating/globals config exists specifically to keep the linter accurate during incremental compiler adoption and around legitimate non-reactive globals — not to weaken the rules.

Connects To

  • Ch 8 (Editor Setup): where this plugin was first flagged as required tooling.
  • Ch 47 (ESLint Rules Reference): what each individual rule actually checks for.
  • Ch 44 (React Compiler — Incremental Adoption): the gating mechanism this plugin's config can mirror.