install
source · Clone the upstream repo
git clone https://github.com/Intense-Visions/harness-engineering
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/Intense-Visions/harness-engineering "$T" && mkdir -p ~/.claude/skills && cp -r "$T/agents/skills/codex/react-hooks-pattern" ~/.claude/skills/intense-visions-harness-engineering-react-hooks-pattern-7e9a59 && rm -rf "$T"
manifest:
agents/skills/codex/react-hooks-pattern/SKILL.mdsource content
React Hooks Pattern
Reuse stateful logic across components via custom hooks
When to Use
- Multiple components share the same stateful logic (e.g., data fetching, form state, media queries)
- You want to extract complex logic from a component to improve readability
- You need to compose behaviors without inheritance or render props
- You are using React 16.8+ (hooks are unavailable in class components)
Instructions
- Identify repeated stateful logic across two or more components.
- Extract it into a function prefixed with
(e.g.,use
,useWindowSize
,useFetch
).useForm - The custom hook must call at least one built-in hook (
,useState
,useEffect
, etc.).useCallback - Return only what the consumer needs — avoid over-exposing internal state.
- Name the hook descriptively after its behavior, not its implementation (
notuseMediaQuery
).useEventListener - Keep hooks pure and side-effect-free at the call site — effects belong inside
.useEffect - Document the hook's return type with TypeScript interfaces.
- Co-locate the hook file with its primary consumer or in a
directory.hooks/
// 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; }
Details
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:
- Hooks compose easily but debugging deep hook stacks can be harder than class-based patterns
- The
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 - React DevTools shows custom hook names in the component tree when they follow the
prefix conventionuse
When NOT to use:
- Logic that does not involve state or effects — extract as a plain utility function instead
- Logic specific to a single component that will never be reused
Related patterns:
- Provider Pattern — hooks often expose context via a
wrapperuseXxx() - Compound Pattern — hooks can manage shared state for compound component groups
Source
https://patterns.dev/react/hooks-pattern
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.