Generate Custom React Hook
Hook name: use$1 (auto-prefix use if not present)
Description: $2
- Check existing hooks:
ls src/hooks/ 2>/dev/null | head -10
Read 1-2 existing hooks to match style.
- Generate the hook:
- Proper TypeScript generics if applicable
- Return type explicitly typed
- Cleanup in
useEffectif subscriptions/listeners involved - Error and loading states if async
- Stable callback references with
useCallback - Memoized values with
useMemowhere appropriate
- Generate a test using
@testing-library/react-hooksorrenderHook.
- Add a usage example comment at the top:
/**
* @example
* const { data, isLoading } = useMyHook(id)
*/
- Place in
src/hooks/use$1.ts(or match project convention).