React Hooks
Create or optimize React hooks for $ARGUMENTS following project conventions.
Task
Analyze the request and create appropriate React hooks:
- •Examine existing hooks: Check project for existing custom hooks patterns and conventions
- •Identify hook type: Determine if creating new custom hook, optimizing existing hook, or implementing specific hook pattern
- •Check TypeScript usage: Verify if project uses TypeScript and follow typing conventions
- •Implement hook: Create hook with proper:
- •Naming convention (use prefix)
- •TypeScript types and interfaces
- •Proper dependency arrays
- •Error handling
- •Performance optimizations
- •Add tests: Create comprehensive unit tests using project's testing framework
- •Add documentation: Include JSDoc comments and usage examples
Common Hook Patterns
When creating hooks, consider these patterns based on the request:
- •Data fetching: API calls, loading states, error handling
- •State management: Local state, derived state, state persistence
- •Side effects: Event listeners, timers, subscriptions
- •Context consumption: Theme, auth, app state
- •Form handling: Input management, validation, submission
- •Performance: Memoization, debouncing, throttling
Requirements
- •Follow existing project hook conventions
- •Use TypeScript if project uses it
- •Include proper cleanup in useEffect
- •Add error boundaries where appropriate
- •Write tests that cover all hook functionality
- •IMPORTANT: Always check existing hooks first to understand project patterns
Notes
- •Ask for clarification if the hook requirements are ambiguous
- •Suggest optimizations for existing hooks if relevant
- •Consider accessibility implications for UI-related hooks