Skip to content
Back to skills

React Hooks

ASecurity

Convert a React class component to a function component using hooks

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 3, 2026
ai-agentsgoreact

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill react-hooks --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React Hooks?

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

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

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
description: Convert a React class component to a function component using hooks
category: frameworks
---

# React Hooks

Reach for this when modernizing a legacy class component into a function component with hooks, preserving behavior exactly.

1. Read the class: note `state` shape, `props` used, lifecycle methods, instance fields, and bound handlers.
2. Replace the class with a function component; turn each piece of `state` into a `useState` call (group related fields only if they update together).
3. Map lifecycles to effects: `componentDidMount`/`componentWillUnmount` → `useEffect(fn, [])` with a cleanup return; `componentDidUpdate` → `useEffect` with the right deps.
4. Convert instance fields that survive renders (timers, refs to DOM/values) to `useRef`; convert methods to inline functions or `useCallback` if passed as props.
5. Remove `this.`, `bind`, and the constructor; read props directly as the function argument.
6. Run the component and its tests; verify effects fire and clean up the same number of times as the old lifecycles.

## Rules
- One `useEffect` per concern, not one giant effect mirroring `componentDidMount`.
- Every value referenced inside an effect must be in its dependency array; do not silence the exhaustive-deps lint by deleting deps.
- `useState` setters are async and don't merge objects — spread manually or split into multiple states.
- Don't wrap everything in `useCallback`/`useMemo`; add them only when an identity actually matters downstream.
- Preserve the original render output and ref-forwarding behavior; use `forwardRef` if the class exposed a ref.

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.

Comments

Loading comments…

Newsletter

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