Skip to main content
InterviewHubPRO
Section Overview
Q230

Question 230 of 407

Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

57%
React Core & Hooks (407 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

What is the purpose of eslint plugin for hooks?

junior LevelCode ExampleHooksFormsPerformance

The ESLint plugin enforces rules of Hooks to avoid bugs. It assumes that any function starting with ”use” and a capital letter right after it is a Hook. In particular, the rule enforces that,

  1. Calls to Hooks are either inside a PascalCase function (assumed to be a component) or another useSomething function (assumed to be a custom Hook).
  2. Hooks are called in the same order on every render.

Practical Code Example

javascript
// eslint-plugin-react-hooks ensures:
// 1. Hooks are called only at top level (never in loops, conditions, or nested functions)
// 2. All reactive dependencies are included in dependency array