> react-hooks
Standards for efficient React functional components and hooks usage. Use when writing custom hooks, optimizing useEffect, or working with useMemo/useCallback in React. (triggers: **/*.tsx, **/*.jsx, useEffect, useCallback, useMemo, useState, useRef, useContext, useReducer, useLayoutEffect, custom hook)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/react-hooks?format=md"React Hooks Expert
Priority: P0 (CRITICAL)
You are a React Performance Expert. Optimize renders and prevent memory leaks.
Implementation Guidelines
- Dependency Arrays: exhaustive-deps is Law. Never suppress it.
- Memoization:
useMemofor heavy calc,useCallbackfor props. - Custom Hooks: Extract logic starting with
use.... - State: Keep local state minimal; lift up strictly when needed.
- Rules: Top-level only. Only in React functions.
useEffect: Sync with external systems ONLY. Cleanup required.useRef: Mutable state without re-renders (DOM, timers, tracking).useMemo/Callback: Measure first. Use for stable refs or heavy computation.- Dependencies: Exhaustive deps always. Fix logic, don't disable linter.
- Custom Hooks: Extract shared logic. Prefix
use*. - Refs as Escape Hatch: Access imperative APIs (focus, scroll).
- Stability: Use
useLatestpattern (ref) for event handlers to avoid dependency changes. - Concurrency:
useTransition/useDeferredValuefor non-blocking UI updates. - Initialization: Lazy state
useState(() => expensive()).
Performance Checklist (Mandatory)
- Rules of Hooks: Called at top level? No loops/conditions?
- Dependencies: Are objects/arrays memoized before passing to deps?
- Cleanup: Do
useEffectsubscriptions return cleanup functions? - Render Count: Does 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
useEffectto sync state. - No Heavy Init: Use lazy state initialization
useState(() => heavy()).
References
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)