Custom React hook with TypeScript generics and full test suite
Views
8.5K
Copies
2.0K
Likes
849
Comments
0
Copy rate
24.0%
Prompt
Build a reusable custom React hook called [hook_name] that [hook_purpose]. Requirements:
- Full TypeScript with generics where applicable
- Proper cleanup on unmount
- Handle loading, error, and success states
- Support cancellation of in-flight requests
- Memoize callbacks to prevent unnecessary re-renders
- Include a comprehensive Vitest test suite with React Testing Library
- Export named only (no default export)
- Handle race conditions (stale closures)Customise this prompt
Fill in 2 variables to personalise this prompt
Preview
Build a reusable custom React hook called [hook_name] that [hook_purpose]. Requirements:
- Full TypeScript with generics where applicable
- Proper cleanup on unmount
- Handle loading, error, and success states
- Support cancellation of in-flight requests
- Memoize callbacks to prevent unnecessary re-renders
- Include a comprehensive Vitest test suite with React Testing Library
- Export named only (no default export)
- Handle race conditions (stale closures)
Example output