react-hooks-patterns
/react-hooks-patterns
Use this skill when implementing custom hooks or managing side effects with useState, useEffect, useMemo, useCallback, and useRef in React.
- Author
- nextboxis ↗
- Repository
- library-skill-agents ↗
- Licence
- MIT
- Last repository change
- 28.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 28.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use this skill when implementing custom hooks or managing side effects with useState, useEffect, useMemo, useCallback, and useRef in React.
Original author description
Use this skill when implementing custom hooks or managing side effects with useState, useEffect, useMemo, useCallback, and useRef in React.
How it works
- When to use
- Prerequisites
- Step-by-step workflow
- Commands / code examples
- Common mistakes & pitfalls
- Verification checklist
- Related skills
SKILL.md preview
---
name: react-hooks-patterns
description: Use this skill when implementing custom hooks or managing side effects with useState, useEffect, useMemo, useCallback, and useRef in React.
---
# React Hooks Patterns
## When to use
Use this skill when encapsulating reusable stateful logic, synchronizing with external APIs or browser events, and optimizing expensive calculations.
## Prerequisites
- React 18+ project environment.
- Familiarity with React component lifecycle and JavaScript closures.
## Step-by-step workflow
1. **Identify stateful behavior**: Extract common side effects or reactive state into a function prefixed with `use`.
2. **Follow rules of hooks**: Call hooks only at the top level of React functions; never inside loops, conditions, or nested functions.
3. **Declare accurate dependencies**: Include every reactive value referenced inside `useEffect`, `useMemo`, or `useCallback` in the dependency array.
4. **Implement effect cleanups**: Always return a cleanup function from `useEffect` to unsubscribe listeners, clear timers, or abort Fetch requests.
5. **Differentiate memoization vs refs**: Use `useRef` for mutable values that do not trigger re-renders; reserve `useMemo` for expensive computations.
## Commands / code examples
```tsx
import { useState, useEffect } from 'react';
export function useWindowDimensions() {
const [dimensions, setDimensions] = useState(() => ({
width: typeof window !== 'undefined' ? window.innerWidth : 0,
height: typeof window !== 'undefined' ? window.innerHeight : 0,
}));
useEffect(() => {
const handleResize = () => {
setDimensions({ width: window.innerWidth, height: window.innerHeight });
};
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return dimensions;
}
```
## Common mistakes & pitfalls
- Omitting values from the dependency array, resulting in stale closures.
- Overusing `useMemo` and `useCallback` for trivial operations, adding memory overhead without performance benefits.
- Setting state synchronously inside `useEffect` without guards, triggering infinite re-render loops.
## Verification checklist
- [ ] Every hook name begins with the `use` prefix.
- [ ] Cleanup functions are returned for all event listeners, timers, and abort controllers.
- [ ] ESLint plugin `react-hooks/exhaustive-deps` passes with zero warnings.
- [ ] Hooks are called strictly at top-level execution scope.
## Related skills
- react-fundamentals
- react-state-management
- performance-code-review-complexity-allocations
- browser-dom-manipulation-events
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · nextboxis/library-skill-agents | 100 | MIT |
| TheBushidoCollective/han | 91 | Apache-2.0 |
Database snapshot: 13.11.2026 · package version 7a5eeee475ea (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100react-patterns
Essential React patterns for hooks, components, and state management. Use when building React components, implementing custom hooks, or debugging state management issues. Covers useState, useEffect, useCallback, useMemo, and context patterns. - 100react-hooks
React Hooks patterns, rules, and custom hook development. Covers all built-in hooks (useState, useEffect, useContext, etc.), performance hooks, and patterns for creating reusable custom hooks. USE WHEN: user mentions "custom hooks", "hook rules", "useState", "useEffect",… - 100react-expert
Expert modern React (18/19): hooks, component design, state, performance, and Server Components. Trigger keywords: React, hooks, useState, useEffect, useMemo, useCallback, useRef, context, re-render, key, Suspense, Server Components, RSC, JSX, stale closure. Use when… - 95frontend-fundamentals
Reviews React/Vue component architecture, state, and hooks. Use when junior builds components, forms, modals, uses useState, useEffect, adds state, or asks "is this good React". - 100hooks-patterns
Use when reasoning about React Hooks as a discipline: why the Rules of Hooks exist as a call-order invariant, how dependency arrays encode a contract between closure and rerender, when useEffect is the wrong primitive, the distinction between derived state and stored state, when… - 100react
React 18+ library for building user interfaces. Covers components, hooks, state management, and rendering patterns. USE WHEN: user mentions "React component", "useState", "useEffect", "hooks", asks about "building UI", "component lifecycle", "React rendering", "JSX" DO NOT USE…