⚙️ 自动化 社区

React 类组件批量重构为函数式组件

使用 Cowork 将旧版 React 类组件转换为函数式组件(含 Hooks),拆分逻辑为自定义 Hooks 并编写测试,5 分钟完成

★★☆ 中级 5-15 min 2026年2月1日
A
AI Blew My Mind @@aiblewmymind
来源
📋

使用场景

开发者有多个旧版 React 类组件需要现代化。Cowork 完成了类到函数的转换、Hooks 迁移、自定义 Hook 拆分和测试编写。

💬

提示词

I have legacy React class components that need to be modernized:
1. Convert all class components to functional components with Hooks
2. Extract reusable logic into custom Hooks
3. Write unit tests for the refactored components
Here are the component files: [attach files]

预期结果

5 分钟完成所有重构,"worked flawlessly"。类组件全部转为函数式,逻辑拆分为自定义 Hooks,测试全部通过。