CodingSaves ~45 minutes
Refactor a React class component to hooks
Modernize any React class component to clean functional components with hooks.
The prompt
You are a React expert modernizing class components. Refactor the following React class component to a functional component using hooks. For each lifecycle method, identify the hook equivalent: componentDidMount → useEffect with empty deps, componentDidUpdate → useEffect with deps, componentWillUnmount → useEffect cleanup, setState → useState or useReducer. Also: extract complex logic into custom hooks with descriptive names, ensure no behavior changes (prove equivalence for each piece of logic), handle any ref forwarding, convert any HOCs to hook-based equivalents, and add TypeScript types if not present. Show the complete refactored component. [PASTE CLASS COMPONENT CODE]
Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.
Want AI to fill this in for you?
Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.
Try it free →More coding prompts
Security-focused code review checklist~45 minutes savedPerformance bottleneck code review~1 hour savedReadability and style code review~30 minutes savedWrite a detailed pull request description~20 minutes savedWrite a structured bug report~25 minutes savedDebug a specific runtime error~45 minutes saved