
Hooks Pattern
Refactor React UIs by pulling shared state, effects, and subscriptions into reusable custom hooks instead of classes or copy-paste logic.
Overview
Hooks Pattern is an agent skill for the Build phase that teaches React Hooks and custom hooks for reusing stateful logic across functional components.
Install
npx skills add https://github.com/patternsdev/skills --skill hooks-patternWhat is this skill?
- Covers `useState` for local state and `useEffect` for side effects in function components
- Custom hooks prefixed with `use` to encapsulate form handling, subscriptions, and shared behavior
- Enforces Rules of Hooks: top-level calls only inside React functions
- Positioned as a cleaner alternative to class components and many legacy patterns (related HOC/render-props skills)
- Scoped tooling: Read, Grep, Glob on TSX/JSX paths with MIT license from patterns.dev v1.1
- Related skills: hoc-pattern and render-props-pattern listed in SKILL.md metadata
Adoption & trust: 554 installs on skills.sh; 218 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You keep copying the same form, subscription, or side-effect logic across React components and want a consistent hooks-based way to share it.
Who is it for?
Solo builders maintaining React 16.8+ apps who want to standardize on function components and custom hooks for shared behavior.
Skip if: Non-React stacks, one-off scripts with no UI, or teams that have already locked a class-only or non-React architecture with no migration plan.
When should I use this skill?
Extracting shared behavior like form handling, subscriptions, or side effects into reusable custom hooks in functional React components.
What do I get? / Deliverables
You get a clear hooks-first approach—local state, effects, and custom `use*` hooks—so components stay composable without class boilerplate.
- Custom hook implementations and refactored components following Rules of Hooks
- Guidance on replacing duplicated stateful logic with composable `use*` hooks
Recommended Skills
Journey fit
Hooks are applied while implementing or refactoring React components during product build, not during distribution or ops. The skill targets `.tsx`/`.jsx` component code, `useState`/`useEffect`, and custom `use*` hooks—core frontend React work.
How it compares
Use as structured procedural guidance for hook extraction instead of ad-hoc Stack Overflow snippets or defaulting to class components.
Common Questions / FAQ
Who is hooks-pattern for?
Frontend-focused solo and indie builders using React who need to reuse stateful logic across components via Hooks and custom hooks.
When should I use hooks-pattern?
During Build when adding state or lifecycle behavior to function components, extracting shared logic (forms, subscriptions, effects), or replacing class-based patterns in `.tsx`/`.jsx` files.
Is hooks-pattern safe to install?
It is a read-and-grep oriented patterns.dev skill with MIT license; review the Security Audits panel on this page and your agent’s tool permissions before broad repo access.
SKILL.md
READMESKILL.md - Hooks Pattern
# Hooks Pattern ## Table of Contents - [When to Use](#when-to-use) - [Instructions](#instructions) - [Details](#details) - [Source](#source) React 16.8 introduced a new feature called [**Hooks**](https://react.dev/reference/react/hooks). Hooks make it possible to use React state and lifecycle methods, without having to use an ES2015 class component. Although Hooks are not necessarily a design pattern, Hooks play a very important role in your application design. Many traditional design patterns can be replaced by Hooks. ## When to Use - Use this when you need to add state or lifecycle behavior to functional components - This is helpful for extracting and reusing stateful logic across multiple components - Use this instead of class components for cleaner, more composable code ## Instructions - Use `useState` for local state and `useEffect` for side effects in functional components - Create custom hooks (prefixed with `use`) to encapsulate and share reusable logic - Follow the Rules of Hooks: only call hooks at the top level and only in React functions - Avoid unnecessary `useEffect` — compute derived state directly in the component body - Let the React Compiler handle memoization instead of manual `useMemo`/`useCallback` where possible ## Details ### Class components Before Hooks were introduced in React, we had to use class components in order to add state and lifecycle methods to components. A typical class component in React can look something like: ```js class MyComponent extends React.Component { /* Adding state and binding custom methods */ constructor() { super() this.state = { ... } this.customMethodOne = this.customMethodOne.bind(this) this.customMethodTwo = this.customMethodTwo.bind(this) } /* Lifecycle Methods */ componentDidMount() { ...} componentWillUnmount() { ... } /* Custom methods */ customMethodOne() { ... } customMethodTwo() { ... } render() { return { ... }} } ``` A class component can contain a state in its constructor, lifecycle methods such as `componentDidMount` and `componentWillUnmount` to perform side effects based on a component's lifecycle, and custom methods to add extra logic to a class. Although we can still use class components after the introduction of React Hooks, using class components can have some downsides! Let's look at some of the most common issues when using class components. #### Understanding ES2015 classes Since class components were the only component that could handle state and lifecycle methods before React Hooks, we often ended up having to refactor functional components into a class components, in order to add the extra functionality. In this example, we have a simple `div` that functions as a button. ```js function Button() { return <div className="btn">disabled</div>; } ``` Instead of always displaying `disabled`, we want to change it to `enabled` when the user clicks on the button, and add some extra CSS styling to the button when that happens. In order to do that, we need to add state to the component in order to know whether the status is `enabled` or `disabled`. This means that we'd have to refactor the functional component entirely, and make it a class component that keeps track of the button's state. ```js export default class Button extends React.Component { constructor() { super(); this.state = { enabled: false }; } render() { const { enabled } = this.state; const btnText = enabled ? "enabled" : "disabled"; return ( <div className={`btn enable