Identify and extract reusable logic into custom hooks
Extract custom hooks from {{COMPONENT_OR_AREA}}:
Current code:
{{CURRENT_CODE_DESCRIPTION}}
Extraction targets:
1. Data fetching logic → useFetch / useQuery hook
2. Form state management → useForm hook
3. Local storage persistence → useLocalStorage hook
4. Debounced search → useDebouncedSearch hook
5. Window size detection → useWindowSize hook
6. Intersection observer → useInView hook
7. Authentication state → useAuth hook
For each extracted hook:
- Define clear TypeScript interface
- Handle cleanup in useEffect return
- Add error handling
- Support AbortController for fetch hooks
- Include loading and error states
Provide:
- Custom hook files with TypeScript types
- Updated component using the new hooks
- Usage examples
- Test cases for each hookImproving code reuse in React projects