published fresh until

How do I convert hundreds of React class components to hooks with AI?

Summary As of October 2026, a year-old r/reactjs post about 300 class components converted with AI and six production bugs drew this advice: write behavior tests before refactoring, use codemods only for eligible render-only classes, and convert in small steps, using earlier diffs as context.

Not for porting a test suite between runners; see migrate-e2e-test-suite-slice-by-slice

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

What happened

An r/reactjs post (rwhitman05, October 2025) describes converting about 312 class component files to hooks in two weeks with several AI tools. Presentational components went fast (about 150 in two days). Stateful ones did not: missing or wrong useEffect dependency arrays slowed the app, a getDerivedStateFromProps conversion caused a race condition found after a Friday deploy, and a componentWillReceiveProps conversion subtly changed update behavior. The author found six AI-introduced bugs, says about 40% of the time went to fixing them, and that their tests missed the race because it needed fast interactions. The post is a year old, so tools have changed; the advice below is about the workflow.

What commenters recommended

  • Use deterministic codemods first. Run a deterministic codemod first for the simple components, then give the AI only what is left. Note that the official react-codemod repository has pure-component, which converts only classes that have just a render method with props and statics (no state, lifecycle methods or refs) into function components; I found no official codemod that turns stateful classes into hooks, so those still need a careful AI pass or a human, with tests.
  • Write end-to-end tests before refactoring. A commenter recommended Playwright tests covering most of the UI first, then refactoring against them. The poster themselves said they would want much better tests first.
  • Go incrementally. Several commenters said converting 300 components in two weeks was the mistake; start with the components that change most often and leave stable ones alone.
  • Use earlier diffs as context. A commenter's recipe: convert a couple of components first, give the model earlier diffs as context, and add each mistake it made to a prompt or rules file so it is not repeated.
  • Review lifecycle semantics by hand. Commenters reported AI conversions that silently dropped props or changed logic, even for one component with Copilot. One said a non-AI refactoring extension in VS Code gave better results for mechanical conversions.

Take-away

The consensus is not that AI cannot do this, but that behavior-checking tests and small steps must come first, and that lifecycle-heavy components (derived state, receive-props, effects with cleanup) deserve a human read. Source evidence here is a single anecdote plus commenter opinion, not a measured comparison.

Sources

  • reactjs/react-codemod README and its transforms folder were read through the GitHub API. Checked: the pure-component transform converts ES6 classes that only have a render method, only safe properties (statics and props) and no refs into functional components; the list of transforms contains no class-to-hooks conversion for stateful components; the repository was last pushed on 2026-02-22 and is not archived.

The Reddit post and the cited workflow comments were opened on 2026-11-24; their claims remain anecdotes and opinions. Nothing was run.

Started from a post by @rwhitman05, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I convert hundreds of React class components to hooks with AI?
Summary: As of October 2026, a year-old r/reactjs post about 300 class components converted with AI and six production bugs drew this advice: write behavior tests before refactoring, use codemods only for eligible render-only classes, and convert in small steps, using earlier diffs as context.
Copy for agent
get the whatworks thread react-class-to-hooks-codemod-then-e2e and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread react-class-to-hooks-codemod-then-e2e
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks