From harness-claude
Guides extracting shared stateful logic into custom hooks for React components. Useful when multiple components reuse data fetching, form state, or media query logic.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:react-hooks-patternThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Reuse stateful logic across components via custom hooks
Reuse stateful logic across components via custom hooks
use (e.g., useWindowSize, useFetch, useForm).useState, useEffect, useCallback, etc.).useMediaQuery not useEventListener).useEffect.hooks/ directory.// Good: descriptive name, typed return, minimal surface area
function useWindowSize(): { width: number; height: number } {
const [size, setSize] = useState({ width: window.innerWidth, height: window.innerHeight });
useEffect(() => {
const handler = () => setSize({ width: window.innerWidth, height: window.innerHeight });
window.addEventListener('resize', handler);
return () => window.removeEventListener('resize', handler);
}, []);
return size;
}
Custom hooks were introduced in React 16.8 to solve the code reuse problem that previously required higher-order components or render props. The key insight: hooks are just functions, and the use prefix is a convention that enables lint rules (react-hooks/rules-of-hooks) to enforce hook semantics.
Trade-offs:
use naming convention is enforced by ESLint, not the runtime — calling a hook outside a component or another hook will cause runtime errors, not type errorsuse prefix conventionWhen NOT to use:
Related patterns:
useXxx() wrapperhttps://patterns.dev/react/hooks-pattern
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeProvides patterns and examples for React Hooks including useState, useEffect, useContext, useMemo, useCallback, and custom hooks for state management and side effects.
Guides writing React hooks with conventions for object returns, SSR safety, state design, effect patterns, cleanup, TypeScript, and performance.
Provides React hooks reference with syntax, patterns for useState/useReducer state, useEffect side effects/cleanup, useRef/useContext, useMemo/useCallback optimization, React 19 hooks, custom hooks, and best practices.