CodingSaves ~40 minutes
Extract a reusable React custom hook
Extract reusable stateful logic into a well-designed custom hook that multiple components can share.
The prompt
You are a React architecture expert. Extract the following stateful logic from a React component into a reusable custom hook. The hook must: follow the 'useXxx' naming convention, accept configuration parameters with sensible defaults, return a consistent and well-typed API object, handle cleanup in useEffect return functions, avoid unnecessary re-renders by stabilizing returned functions with useCallback and values with useMemo, include TypeScript generics where the hook can work with different data types, and be accompanied by a JSDoc comment and a usage example. Also write tests for the hook using React Testing Library's renderHook. Logic to extract: [DESCRIBE OR PASTE THE LOGIC] Component it currently lives in: [PASTE COMPONENT OR DESCRIBE] Desired hook name: [useXxx]
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