react-hooks
Write efficient React functional components and hooks. Use when writing custom hooks, optimizing useEffect, or working with useMemo/useCallback in React.
What this skill does
# React Hooks Expert ## **Priority: P0 (CRITICAL)** **Role**: React Performance Expert. Optimize renders, prevent memory leaks. ## Implementation Guidelines - **Dependency Arrays**: exhaustive-deps Law. **Objects/arrays recreated each render**, causing **infinite loops** if not handled. Fix by ensuring **objects/arrays memoized** with **`useMemo`** before putting them in deps, or using **`useRef`** for stable refs. - **Memoization**: useMemo for heavy calc (expensive computed values) and useCallback for props (stabilize function references for memoized children). **Measure first** to avoid premature complexity. - **Custom Hooks**: Extract logic starting with use... — use `useState` for internal state and return only what's needed. - **`useEffect`**: Sync with external systems ONLY. **Cleanup required** for subscriptions/event listeners. **Return cleanup function** from effect. Use **`AbortController`** for fetch cleanup to prevent state updates after unmount. - **`useRef`**: Mutable state without re-renders (DOM, timers, tracking). - **`useMemo`/`Callback`**: Measure first. Use for stable refs or heavy computation. - **Stability**: Use `useLatest` pattern (ref) for event handlers to avoid dependency changes; see [useLatest ref pattern example](https://react.gg/hooks/use-latest-ref) for reference implementation. - **Concurrency**: `useTransition` / `useDeferredValue` for non-blocking UI updates. - **Initialization**: Lazy state `useState(() => expensive())`. ## Performance Checklist (Mandatory) - [ ] **Rules of Hooks**: Called at top level? No loops/conditions? - [ ] **Dependencies**: objects/arrays memoized before passing to deps? - [ ] **Cleanup**: `useEffect` subscriptions return cleanup functions? - [ ] **Render Count**: component re-render excessively? ## Anti-Patterns - **No Missing Deps**: Fix logic, don't disable linter. - **No Complex Effects**: Break tailored effects into smaller ones. - **No Derived State**: Compute during render, don't `useEffect` to sync state. - **No Heavy Init**: Use lazy state initialization `useState(() => heavy())`. ## References - [Optimization Patterns](references/REFERENCE.md)
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.