migrate-class-to-hooks

migrate-class-to-hooks is a skill for Claude Code, Codex from Phaedra-Solutions/cursor-rules. It costs 111 tokens per session (1,027 once invoked), scanned A, original, MIT.

A step-by-step guide for converting React class components into function components that use hooks, React features for state and lifecycle behaviour.

In plain words
What is it for?
Use it to migrate components incrementally, map state and lifecycle code to hooks, and keep error boundaries as classes when needed.
Why use it?
It preserves visible behaviour by testing the class version first and provides a way to handle state, lifecycle methods, references, and cleanup during the conversion.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to migrate components incrementally, map state and lifecycle code to hooks, and keep error boundaries as classes when needed.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/phaedra-solutions/cursor-rules/migrate-class-to-hooks
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Phaedra-Solutions/cursor-rules --skill migrate-class-to-hooks
Clone the repo
git clone --depth 1 https://github.com/Phaedra-Solutions/cursor-rules

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for migrate-class-to-hooks

README.md
[![agentmods](https://agentmods.dev/badge/skills/phaedra-solutions/cursor-rules/migrate-class-to-hooks/github.svg)](https://agentmods.dev/skills/phaedra-solutions/cursor-rules/migrate-class-to-hooks)
Your own site
<a href="https://agentmods.dev/skills/phaedra-solutions/cursor-rules/migrate-class-to-hooks"><img src="https://agentmods.dev/badge/skills/phaedra-solutions/cursor-rules/migrate-class-to-hooks/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for migrate-class-to-hooks

Your own site · 80×15
<a href="https://agentmods.dev/skills/phaedra-solutions/cursor-rules/migrate-class-to-hooks"><img src="https://agentmods.dev/badge/skills/phaedra-solutions/cursor-rules/migrate-class-to-hooks.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 111 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,027 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00111 $0.01027
Opus 5.5 $0.00044 $0.00411
Sonnet 5.5 $0.00022 $0.00205
Haiku 4.5 $0.00011 $0.00103

Measured 3d ago against content hash 46a030bade58, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

migrate-class-to-hooks scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/migrate-class-to-hooks/SKILL.md · 59 lines

How it starts

The opening of the file, as written. The whole thing — 59 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Migrate class components → hooks

When to use

  • The user asks to convert class components, or a class component needs substantial changes anyway.
  • React is 16.8 or newer (hooks exist). Error boundaries stay classes (there's no hook equivalent).

Before you start

  • Pick the scope with the user: one component (default), a feature folder, or leaf components first across the app. Never the whole app in one change.
  • Read the component, its parents and tests. Note lifecycle methods, setState callbacks, instance fields, refs, context (contextType, Consumer), HOCs (connect, withRouter) and getDerivedStateFromProps.
  • Working tree clean; new branch.

Steps

  1. Characterization tests: if the component lacks tests, add Testing Library tests for its visible behavior (render output, user interactions, calls to props and APIs) and make them pass on the class version first.
  2. Convert the shell: class X extends Component → function X(props) (or a typed arrow function per house style); destructure props; move defaultProps to default parameter values.
  3. State: each independent this.state field → useState; related fields or complex transitions → useReducer. Replace this.setState(prev => …) with functional updates. setState(…, callback) → do the follow-up in the event handler or an effect keyed on that state.
  4. Lifecycle:
    • work that responds to a user action → the event handler, not an effect;
    • derived data → compute during render (useMemo only if measured slow, or let React Compiler handle it);
    • subscriptions, timers, DOM integrations: componentDidMount + componentWillUnmount → one useEffect with cleanup;
    • componentDidUpdate(prevProps) comparisons → useEffect with those values as dependencies;
    • getDerivedStateFromProps → derive during render, or reset state with a key on the component;
    • shouldComponentUpdate/PureComponent → memo() only if needed. Include every value the effect uses in its dependency array; don't silence react-hooks/exhaustive-deps.
  5. Instance fields and refs: mutable instance fields (this.timer) → useRef; createRef → useRef; callback refs stay callback refs; forwardRef only on React < 19 (19 passes ref as a prop).
  6. Context and HOCs: static contextType/Consumer → useContext; connect(mapState, mapDispatch) → useSelector/useDispatch (keep selectors memoized); withRouter → the router's hooks (useNavigate, useParams).
  7. Run the tests, fix differences, and check effects don't run twice incorrectly under StrictMode (cleanup must undo setup).
  8. Verify (next section); show the diff and results; commit only when asked (git-commit skill).

Read the full file on GitHub · 59 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 59 lines · 111 tokens per session scan A 46a030bade58

Subscribe to this mod's changes

migrate-class-to-hooks is a skill published in the GitHub repository Phaedra-Solutions/cursor-rules (4 stars, last pushed 2d ago), licensed MIT. It adds 111 tokens to every session and 1,027 once invoked, about $0.0004 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-01.