Skip to main content
These rules catch common mistakes with useState, useEffect, and related hooks that lead to bugs, performance issues, or unnecessary re-renders.

Rules

Severity: error
Rule ID: react-doctor/no-derived-state-effect
Detects state that is derived from props or other state inside useEffect. This pattern is almost always wrong.Why it’s bad:
  • Creates an extra render cycle
  • State updates happen after render instead of during
  • Can cause infinite loops if dependencies aren’t perfect
Bad:
Good:
Or use a key to reset component state:
Severity: error
Rule ID: react-doctor/no-fetch-in-effect
Prevents using fetch() directly inside useEffect. Manual data fetching leads to race conditions, missing loading states, and no caching.Why it’s bad:
  • Race conditions when component unmounts
  • No automatic deduplication or caching
  • Missing loading/error states
  • Waterfall requests
Bad:
Good:
Severity: warn
Rule ID: react-doctor/no-cascading-set-state
Flags useEffect containing 3 or more setState calls. This indicates state that should be managed together.Why it’s bad:
  • Multiple setState calls = multiple re-renders
  • Hard to keep state synchronized
  • Suggests missing abstraction
Bad:
Good:
Severity: warn
Rule ID: react-doctor/no-effect-event-handler
Detects useEffect that runs only when a specific value changes and contains a single if statement. This is usually an event handler in disguise.Bad:
Good:
Severity: warn
Rule ID: react-doctor/no-derived-useState
Catches useState initialized directly from a prop value. If the prop changes, state won’t update.Bad:
Good:
Severity: warn
Rule ID: react-doctor/prefer-useReducer
Suggests using useReducer when a component has 5+ useState calls for related state.Bad:
Good:
Severity: warn
Rule ID: react-doctor/rerender-lazy-state-init
Enforces lazy initialization for useState when initialized with a function call. The function runs on every render even though only the first result is used.Bad:
Good:
Severity: warn
Rule ID: react-doctor/rerender-functional-setstate
Requires using functional updates when the new state depends on the old state to avoid stale closures.Bad:
Good:
Severity: error
Rule ID: react-doctor/rerender-dependencies
Catches object literals and array literals in dependency arrays. These create new references every render, causing the effect to run infinitely.Bad:
Good: