react-class-to-hooks-migrator
Installation
SKILL.md
Class → Hooks Migrator
Phase 1 — THINK
This migration's real risk isn't syntax — it's that componentDidUpdate and useEffect have different mental models, and a naive conversion silently introduces stale closures or infinite re-render loops.
- For every class component being converted, list its lifecycle methods and, critically, what each one depends on reading (props/state) at the time it runs
- Specifically check
componentDidUpdatelogic that does conditional work based on comparing prev/current props or state — this needs to become auseEffectwith a carefully chosen dependency array, not a blind "run every update" - Check for
this.instancevariables that aren't state (timers, subscriptions, mutable refs) — these map touseRef, notuseState, and mixing them up is a common bug source - Flag any component using legacy lifecycle methods (
componentWillReceiveProps,componentWillMount) — these need a real redesign, not a mechanical hook swap
Phase 2 — PLAN
For each component, show before starting:
- State →
useState/useReducermapping (recommenduseReducerif there are more than ~3 interdependent state values, since that's whereuseStatesprawl gets buggy) - Lifecycle →
useEffectmapping, with the dependency array explicitly reasoned about per effect, not left as an afterthought - Instance variables →
useRefmapping - Any behavior that's genuinely ambiguous to convert safely (e.g., subtle timing in
componentDidUpdate) flagged for the user to confirm intent before converting