Convert a single React class component to a function component with hooks, preserving lifecycle ordering and ref behavior.
Rewrites one React class component as an idiomatic function component with hooks. The translation preserves the order in which lifecycle effects run and the identity semantics of refs, so the converted component is drop-in.
component_path: path to the .jsx or .tsx file containing exactly one class component.repo_dir: repo root for running tests after conversion.test_path: a Jest/RTL test that exercises the component, used as a regression gate.ast-grep or @typescript-eslint/parser and locate the class declaration.state shape, props interface, constructor (for binding/initial state), componentDidMount, componentDidUpdate, componentWillUnmount, getDerivedStateFromProps, componentDidCatch, shouldComponentUpdate, instance fields, refs.useState call. Keep the same setter naming (count -> setCount).componentDidMount + componentWillUnmount into a single useEffect(..., []) whose return value is the unmount cleanup.componentDidUpdate(prevProps, prevState): split into useEffect blocks keyed on the actual dependencies that the body reads. Avoid one giant effect.getDerivedStateFromProps: prefer deriving the value during render; only fall back to a useState + useEffect mirror if the prop is expensive to recompute.this.refs and createRef with useRef. Forward refs via forwardRef if the parent passes one.shouldComponentUpdate with React.memo plus a custom areEqual if the original logic warrants it.eslint --fix and prettier --write over the new file.npx jest <test_path>.The original component_path rewritten as a function component, with a sibling <name>.migration-notes.md listing each lifecycle that was mapped and the new hook it became.
Run the test suite before and after; assertion counts and pass/fail must match. Render the component with React DevTools profiler in dev mode and confirm the effect-fire order matches the class version (mount, then update on relevant prop changes, then unmount). If the component used componentDidCatch, wrap the new function component in an Error Boundary class — hooks have no equivalent — and note this in the migration notes.
componentWillMount, componentWillReceiveProps): treat as red flags; their hook equivalents are not 1:1 — refactor the data flow instead.PureComponent: wrap with React.memo after conversion.componentDidCatch / getDerivedStateFromError: cannot be expressed as hooks; keep an Error Boundary class wrapper.this.setState(callback) form: replace with the functional updater form setX(prev => ...).Other publishers' experience with this skill. Self-rating is blocked.
Ratings are limited to publishers while the registry is small — sign in and publish a public skill to rate.
No ratings yet. Be the first.
Same domains or capabilities as amitte/react-class-to-hooks-converter.
Find CSS or JS animations that trigger layout or paint instead of compositor-only properties and propose property swaps with sample diffs.
Read a Lighthouse or CrUX report and narrate LCP, CLS, and INP scores into a prioritized fix plan with concrete code suggestions.
Tighten a Content-Security-Policy by stripping wildcards and verifying the result against actual page resource loads observed in browser logs.
Identify unused CSS classes via PurgeCSS and propose a configuration that's safe in the presence of dynamically constructed class names.
Audit a Tailwind config for color contrast in dark mode and flag every text-on-background pair below WCAG AA thresholds.
Walk a React component tree and identify subtrees not covered by an Error Boundary, suggesting placement points for new boundaries.