djankies/claude-configs/following-the-rules-of-hooks
Claude Code and agent skill by djankies/claude-configs
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Fix React Rules of Hooks violations - conditional calls, hooks in loops/callbacks/classes
Install
npx vskill@latest install djankies/claude-configs/following-the-rules-of-hooksSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as majiayu000/claude-skill-registry/following-the-rules-of-hooks.
Rules of Hooks
React enforces two invariants on Hook usage. Violating these causes state corruption and unpredictable behavior.
The Rules
- Top-level only - Never call Hooks inside loops, conditions, nested functions, or try/catch/finally
- React functions only - Call Hooks exclusively from function components or custom Hooks
Why: Consistent call order across renders; conditional/dynamic invocation breaks state tracking.
Valid Hook Locations
✅ Top level of function components ✅ Top level of custom Hooks (use* functions)
Common Violations
| Violation | Why Invalid | Fix | |
|---|---|---|---|
| Inside if/else | Skipped on some renders | Move to top; use conditional rendering | |
| Inside loops | Variable call count | Move to top; manage array state | |
| After early return | Unreachable on some paths | Move Hook before return | |
| In event handlers | Called outside render | Move to top; use state from closure | |
| In class components | Classes don't support Hooks | Convert to function component | |
| Inside callbacks | Nested function context | Move Hook to top level |
Common Fixes
Conditional Hooks
❌ Wrong:
✅ Right:
Pattern: Always call Hook, use conditional rendering for output.
Hooks in Loops
❌ Wrong:
✅ Right:
Pattern: Single Hook managing collection, not per-item Hooks.
Hooks in Event Handlers
❌ Wrong:
✅ Right:
Pattern: Hook at component level, setter in handler.
Hooks in Classes
❌ Wrong:
✅ Right:
Pattern: Use function components for Hooks.
Hooks in Callbacks
❌ Wrong:
✅ Right:
Pattern: Call Hook at top level, reference in callback.
Hooks After Early Returns
❌ Wrong:
✅ Right:
Pattern: Call all Hooks before any returns.
Custom Hooks
Custom Hooks may call other Hooks because they execute during render phase:
Requirements: Name starts with use; called from function component or another custom Hook; follows same Rules of Hooks.
Quick Diagnostic
ESLint error: "React Hook cannot be called..."
- Check location: Is Hook inside if/loop/try/handler/class?
- Move Hook to top level of component/custom Hook
- Keep conditional logic, move Hook call outside it
- Use conditional rendering, not conditional Hooks
Reference: https://react.dev/reference/rules/rules-of-hooks
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingreact-19/skills/following-the-rules-of-hooks/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/djankies/claude-configs/following-the-rules-of-hooks)