hooks-pattern

Guides extraction of stateful React logic into reusable custom hooks.

1|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/TierOne-Studio/spa-velocity --skill hooks-pattern-tierone-studio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hooks-pattern
Source: https://github.com/TierOne-Studio/spa-velocity/tree/main/.ruler/skills/hooks-pattern
Command: npx skills add https://github.com/TierOne-Studio/spa-velocity --skill hooks-pattern-tierone-studio

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? React components often accumulate tangled stateful logic, duplicated lifecycle code, and wrapper hell from HOC or render-props patterns. This Skill helps you decide when and how to extract that logic into clean, reusable custom hooks. ## Core Features & Use Cases - Custom Hook Design: Guidance for extracting state, subscriptions, and side effects into reusable use* functions following the Rules of Hooks. - Hook vs Component vs Server-State Decisions: Criteria for judging whether behavior belongs in a hook, a component, or a server-state query. - Class-to-Hooks Migration: Patterns for refactoring class components with lifecycle methods into functional components using useState and useEffect. - Use Case: You notice three components duplicating the same window-resize subscription logic. Use this Skill to extract it into a single useWindowWidth hook and remove the duplication. ## Quick Start Review this component and extract its reusable stateful logic into a custom hook following the hooks-pattern guidance.

Frequently Asked Questions about hooks-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a custom React hook?

Create a function prefixed with `use` that calls built-in hooks like useState or useEffect and returns the values consumers need. For example, a useKeyPress hook encapsulates event listener setup and cleanup, returning a boolean any component can reuse.

When should I extract logic into a custom hook?

Extract a custom hook when the same stateful logic, subscription, or side effect appears in multiple components. Plain helper functions, one-off component state with no reuse signal, and inline useState calls do not warrant a custom hook.

What are the Rules of Hooks in React?

Hooks must only be called at the top level of a function, never inside loops, conditions, or nested functions. They must only be called from React function components or other custom hooks, and custom hooks must start with `use` so linting can verify compliance.

Should I use useMemo and useCallback for performance?

Prefer letting the React Compiler handle memoization automatically instead of adding manual useMemo and useCallback calls. Manual memoization is frequently misused and adds complexity without measurable benefit in most components.

When should logic stay in a component instead of a hook?

Keep logic in the component when it is component-specific state with no reuse across the codebase, or when it is a plain helper function with no hook calls. Derived state should be computed directly in the component body rather than in useEffect.