Custom React hook with TypeScript generics and full test suite
Views
9.5K
Copies
2.9K
Likes
1.0K
Comments
0
Copy rate
30.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