Skip to content
Back to skills

React Hooks Patterns

ASecurity

Writes custom React hooks with honest dependency arrays, proper cleanup and no stale closures, and fixes effects that misuse useEffect.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 15, 2026
ai-agentsreactapi

Works with

  • api

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill react-hooks-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React Hooks Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for React Hooks Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-react-hooks-patterns/badge)](https://www.skillsdirectory.com/skills/workspace-templates-react-hooks-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: react-hooks-patterns
description: Writes custom React hooks with honest dependency arrays, proper cleanup and no stale closures, and fixes effects that misuse useEffect.
---

# React hooks patterns

Most effects should not exist. Write the ones that do so they are safe to run twice.

## Steps

1. For every `useEffect` ask what it synchronizes with. If the answer is "state with other state", delete it and compute the value during render, or use `useMemo` if it is costly. If the answer is "a user action", move it into the event handler.
2. For real synchronization (subscription, timer, network, DOM API) write setup and cleanup as a pair. Unsubscribe, clear timers, abort fetches with `AbortController`, and ignore results of outdated requests.
3. Make the dependency array complete. Never silence `react-hooks/exhaustive-deps`. If a dependency causes unwanted reruns, fix its source: move the object or function inside the effect, memoize it at the owner, or read the latest value through a ref (`useRef` updated in an effect) or `useEffectEvent` where available.
4. Prevent stale closures: use the functional form `setCount(c => c + 1)` when new state depends on old state, and do not capture props in long-lived callbacks without listing them.
5. Extract a custom hook only when logic repeats or hides a lifecycle. Name it `useThing`, return a stable shape (object for many values, tuple for two), and keep it free of JSX.
6. Verify in Strict Mode: mount, unmount, remount must leave no duplicate listeners or requests.

## Rules

- Hooks are called at the top level, never in conditions or loops.
- Do not fetch in effects if the project has a data library; use it.
- Add a test with `renderHook` for each new hook.

## Report

Effects removed, hooks extracted, bugs fixed and tests added.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.