Skip to content
Back to skills

Extract Hook

ASecurity

Moves stateful logic out of a React component into a custom hook, keeps behavior identical and adds tests for the hook.

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

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill extract-hook --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Extract Hook?

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

Security grade badge for Extract Hook
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-extract-hook-ai-agent-templates/badge)](https://www.skillsdirectory.com/skills/workspace-templates-extract-hook-ai-agent-templates)

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: extract-hook
description: Moves stateful logic out of a React component into a custom hook, keeps behavior identical and adds tests for the hook.
disable-model-invocation: true
---

Extract a custom hook from the component: $ARGUMENTS

1. Read the component. Group the `useState`, `useReducer`, `useEffect`, `useMemo` and `useCallback` calls by purpose. Pick the group that has no JSX dependency, or the one named in the arguments.
2. Name the hook `use` plus what it manages (`useDebouncedSearch`, not `useLogic`). Place it next to the component or in the project's hooks folder, following existing files.
3. Move the code unchanged first. Return only what the component needs, as an object for more than two values. Pass inputs as parameters; do not read from outer scope.
4. Preserve effect cleanup and dependency arrays exactly. Run the exhaustive-deps lint rule and fix real warnings.
5. Write tests with `renderHook` (Testing Library) covering the initial state, one update and cleanup on unmount.

Run the component's existing tests, the new hook tests and the type check. Report the hook's signature and any behavior you suspect was already buggy but left alone.

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.