Decouple UI from business logic
Extract business logic from a UI component into a service or custom hook. Leaves the component responsible only for rendering and event delegation.
Preview
Copy prompt
The following component couples UI rendering directly with business logic, making it difficult to test either in isolation: [Paste code]. Extract the business logic into a dedicated service layer or custom hook, leaving the component responsible solely for rendering and event delegation. Show the refactored component and the extracted logic as separate files, and demonstrate how the logic can now be unit-tested without mounting the component.
More
Refactoring
Prompts
