Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

react

БесплатноБез исполняемых скриптовНе проверен

How to use React. Use when working on a React codebase.

elentokот elentok★ 25 звёзд на GitHub

Об этом скилле

React Best Practices & Composition Patterns

Based on Vercel Agent Skills


Part 1: React Best Practices

1. Eliminating Waterfalls (CRITICAL)

  • Defer await until needed — move await into the branch that uses the result; don't block early-return paths.
  • Parallelize with Promise.all() — never await independent operations sequentially; run them concurrently.
  • Dependency-based parallelization — for partial dependencies, start promises eagerly and Promise.all() at the end:
    const userPromise = fetchUser()
    const profilePromise = userPromise.then((u) => fetchProfile(u.id))
    const [user, config, profile] = await Promise.all([userPromise, fetchConfig(), profilePromise])
    
  • Strategic Suspense boundaries — wrap only the data-dependent section in <Suspense> so layout renders immediately. Share promises across sibling components via use().

2. Bundle Size Optimization (CRITICAL)

  • Avoid barrel file imports — import directly from source (lucide-react/dist/esm/icons/check) instead of barrel re-exports. Barrel imports can load 1,500+ modules.
  • Dynamic imports for heavy components — use React.lazy / next/dynamic with { ssr: false } for large components (editors, charts).
  • Defer non-critical libraries — load analytics/logging after hydration via dynamic import.
  • Preload on user intent — trigger import() on onMouseEnter/onFocus to reduce perceived latency.
  • Conditional module loading — import() large data/modules only when a feature is activated.

3. Server-Side Performance (HIGH)

  • Authenticate Server Actions — treat "use server" functions as public endpoints; always verify auth + authorization inside each action.
  • Minimize serialization at RSC boundaries — only pass the fields the client component actually uses, not entire objects.
  • Parallel data fetching with component composition — make the parent a sync component that renders async children in parallel (not a sequential async parent).
  • Per-request dedup with React.cache() — wrap DB queries/auth checks; avoid inline objects as args (uses Object.is).
  • Hoist static I/O to module level — fonts, logos, config files read once at import, not per-request.
  • Use after() for non-blocking ops — schedule logging/analytics after the response is sent.

4. Client-Side Data Fetching (MEDIUM-HIGH)

  • Use SWR for automatic request deduplication, caching, and revalidation across component instances.
  • Passive event listeners — add { passive: true } to touch/wheel listeners that don't call preventDefault().
  • Deduplicate global event listeners — use a shared subscription (e.g., useSWRSubscription) instead of N listeners for N component instances.
  • Version localStorage keys — prefix with version, store minimal fields, always wrap in try-catch.

5. Re-render Optimization (MEDIUM)

  • Derive state during render — if computable from props/state, don't store in state or sync via useEffect.
  • Don't define components inside components — creates new component type every render, destroying state/DOM.
  • Functional setState updates — setState(prev => ...) avoids stale closures and removes state from dependency arrays.
  • Lazy state initialization — useState(() => expensive()) runs only once; without the arrow, it runs every render.
  • Split combined hook computations — separate useMemo/useEffect with independent deps so they recompute independently.
  • Subscribe to derived state — e.g., useMediaQuery('(max-width:767px)') instead of subscribing to continuous width changes.
  • Extract default non-primitive values to constants — const NOOP = () => {} as default prop for memo()'d components.
  • Use useRef for transient values — mouse position, interval IDs, flags that shouldn't trigger re-renders.
  • useDeferredValue for expensive derived renders — keeps input responsive while heavy computation catches up.
  • startTransition for non-urgent updates — marks frequent state updates (scroll, resize) as interruptible.
  • Put interaction logic in event handlers — not as state + effect; avoids duplicate side effects.

6. Rendering Performance (MEDIUM)

  • CSS content-visibility: auto — skip layout/paint for off-screen items in long lists (10× faster initial render for 1000 items).
  • Animate SVG wrapper div, not SVG element — enables hardware-accelerated CSS transforms.
  • Hoist static JSX — extract constant JSX outside components to avoid re-creation.
  • <Activity mode="visible|hidden"> — React API to preserve state/DOM for toggled components.
  • defer/async on scripts — never block HTML parsing with synchronous script tags.
  • Explicit conditional rendering — use ternary (? :) not && when condition can be 0 or NaN.
  • **React DOM resource
Полный SKILL.md на GitHub

Установить react в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл react?

How to use React. Use when working on a React codebase.

Как установить скилл react?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл react запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить react с