본문으로 건너뛰기
cccskills
무료GitHub에 공개

react-best-practices

Write, review, or refactor React code using prioritized guidance for data fetching, bundle size, rendering, component structure, testing, and type safety. Start with high-impact issues such as sequential requests and unnecessary library loading.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

React performance optimization guidelines from Mastra Engineering. This skill should be used when writing, reviewing, or refactoring React code to ensure optimal performance patterns. Triggers on tasks involving React components, data fetching, bundle optimization, or performance improvements.

설치 방법 보기

이럴 때 유용합니다

  • Writing React components and data-fetching logic
  • Reviewing code for loading and rendering performance
  • Refactoring large components and overly broad interfaces
  • Checking test practices and TypeScript type safety

포함된 파일(29)

  • SKILL.md7.3 KB
  • references/react-best-practices-reference.md17.4 KB
  • references/rules/async-parallel.md650 B
  • references/rules/bundle-barrel-imports.md1.5 KB
  • references/rules/bundle-defer-third-party.md978 B
  • references/rules/client-request-dedupe.md3.6 KB
  • references/rules/js-length-check-first.md1.7 KB
  • references/rules/js-set-map-lookups.md532 B
  • references/rules/js-tosorted-immutable.md1.7 KB
  • references/rules/rendering-animate-svg-wrapper.md1.1 KB
  • references/rules/rendering-content-visibility.md823 B
  • references/rules/rerender-lazy-state-init.md2.0 KB
  • references/rules/rerender-no-setstate-in-render-or-effect.md3.0 KB
  • references/rules/rerender-no-useeffect-state-reset.md3.0 KB
  • references/rules/rerender-no-usememo-usecallback.md2.5 KB
  • references/rules/rerender-transitions.md1.0 KB
  • references/rules/rerender-useeffect-function-calls.md1.8 KB
  • references/rules/structure-complex-derived-logic.md10.0 KB
  • references/rules/structure-component-naming.md1.6 KB
  • references/rules/structure-composition-over-config.md3.1 KB
  • references/rules/structure-data-fetching-layout.md4.6 KB
  • references/rules/structure-derive-dont-duplicate.md1.5 KB
  • references/rules/structure-early-return-render-branches.md3.3 KB
  • references/rules/structure-narrow-apis.md4.1 KB
  • references/rules/structure-single-responsibility.md4.1 KB
  • references/rules/testing-bdd-no-mocks.md6.8 KB
  • references/rules/testing-no-classname-assertions.md3.6 KB
  • references/rules/types-no-null.md2.8 KB
  • references/rules/types-no-type-assertions.md4.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

React Best Practices

Overview

Routing and priority guide for React performance and quality, containing 27 rules across 9 categories. Rule files hold the detailed explanations, examples, review smells, and impact metrics.

When to Apply

Reference these guidelines when:

  • Writing new React components
  • Implementing data fetching
  • Reviewing code for performance issues
  • Refactoring existing React code
  • Optimizing bundle size or load times

Priority-Ordered Guidelines

Rules are prioritized by impact:

PriorityCategoryImpact
1Eliminating WaterfallsCRITICAL
2Bundle Size OptimizationCRITICAL
3Client-Side Data FetchingMEDIUM-HIGH
4Re-render OptimizationMEDIUM
5Rendering PerformanceMEDIUM
6JavaScript PerformanceLOW-MEDIUM
7Component StructureMEDIUM-HIGH (maintainability)
8TestingMEDIUM-HIGH (correctness)
9Type SafetyHIGH

Quick Reference

Critical Patterns (Apply First)

Eliminate Waterfalls:

  • Use Promise.all() for independent async operations (async-parallel)

Reduce Bundle Size:

  • Avoid barrel file imports, import directly from source (bundle-barrel-imports)
  • Defer non-critical third-party libraries (bundle-defer-third-party)

Medium-Impact Patterns

Client-Side Data Fetching:

  • Use Tanstack Query for automatic request deduplication (client-request-dedupe)
  • Dependent query params are the value or undefined, never | null or a fake fallback; narrow at the caller so hooks stay strict, or guard with skipToken when the hook must accept an optional param (client-request-dedupe)

Re-render Optimization:

  • Use lazy state initialization for expensive values (rerender-lazy-state-init)
  • Apply startTransition for non-urgent updates (rerender-transitions)
  • Keep UI handlers plain; use Effect Events only for effect-fired logic (rerender-useeffect-function-calls)
  • Never reset state with useEffect; lift the discriminant and remount the branch (rerender-no-useeffect-state-reset)
  • Never add useMemo or useCallback; leave memoization decisions to developers with profiler evidence (rerender-no-usememo-usecallback)
  • Never call setState during render or inside useEffect; derive during render or move state ownership to an intermediate component (rerender-no-setstate-in-render-or-effect)

Component Structure:

  • One domain component/hook per file, one responsibility each — split bloated components (structure-single-responsibility)
  • Keep component, hook, function, and utility APIs narrow: split oversized props, arguments, and return objects into focused units composed at the component level; wrapping the same values in one object is not a fix (structure-narrow-apis)
  • Use PascalCase components for JSX-returning helpers; keep lowercase helpers for non-JSX values (structure-component-naming)
  • Derive props/params instead of accepting a value computable from another arg (structure-derive-dont-duplicate)
  • Extract complex derived logic into named locals plus predicates or pure helpers with early returns: oversized conditions, nested ternaries, ternaries that compute instead of picking (multi-line branches, or an as cast re-asserting what the condition tested), fallback chains, and let-based render prep are code smells, in render prep and in hook options, request builders, config maps, and reducers alike (structure-complex-derived-logic)
  • Pick the view with early if guards but keep the layout wrapper in one place — branch a body component, don't ternary or duplicate the shell (structure-early-return-render-branches)
  • For a fixed set of items, write one component per item with explicit props that owns its data and loading — don't map a config-object array onto a component shape (structure-composition-over-config)
  • When a domain component fetches data, render through a pure layout component that positions slots, and branch the slot contents between skeletons and resolved sub-domain components (structure-data-fetching-layout)

Testing:

  • BDD tests that drive the real @mastra/client-js + React Query stack and mock only the network; never vi.mock our own hooks/services/auth gating or the SDK (testing-bdd-no-mocks)
  • Avoid class-name assertions for visual behavior; prefer computed styles, user-visible behavior, or browser validation, and prefer no test over a className-only implementation mirror (testing-no-classname-assertions)

Type Safety:

  • No as type assertions anywhere — production or tests; narrow with real type guards, query generics (querySelector<T>, getByRole<T>), typed fixture factories, or implements on mocks. as const is the only allowed form. Do not replace a cast with a domain-type predicate that only checks typeof value === 'object'; call that an isRecord helper or validate the fields used (types-no-type-assertions)
  • Use undefined and optional ? for absence, not null; convert external null at boundaries, and keep leaf props strict so callers own absence and fallback rendering (types-no-null)

Rendering Patterns

  • Animate SVG wrappers, not SVG elements directly (rendering-animate-svg-wrapper)
  • Use content-visibility: auto for long lists (rendering-content-visibility)

JavaScript Patterns

  • Use Set/Map for repeated lookups (js-set-map-lookups)
  • Use toSorted() instead of sort() for immutability (js-tosorted-immutable)
  • Early length check for array comparisons (js-length-check-first)

References

Rule files are the canonical source for detailed guidance and examples:

  • references/react-best-practices-reference.md - Rule catalog with category order and rule-file paths
  • references/rules/ - Canonical individual rule files organized by category

Load only the relevant rule file when implementing or reviewing a specific pattern. Use the catalog to choose the right rule without loading every example.

To look up a specific pattern, grep the rules directory:

grep -l "Promise.all" references/rules/
grep -l "barrel" references/rules/
grep -l "Tanstack" references/rules/

Rule Categories in references/rules/

  • async-* - Waterfall elimination (1 rule)
  • bundle-* - Bundle size optimization (2 rules)
  • client-* - Client-side data fetching (1 rule)
  • rerender-* - Re-render optimization (6 rules)
  • rendering-* - DOM rendering performance (2 rules)
  • js-* - JavaScript micro-optimizations (3 rules)
  • types-* - Type-safety / no-as-cast and no-null rules (2 rules)
  • structure-* - Component/hook/function/utility structure (8 rules)
  • testing-* - BDD tests + mock-only-the-network policy + no className implementation-mirror assertions (2 rules)

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Design and audit an agent's system prompt, the instructions that guide its work. Define a concrete outcome, starting input, available tools, completion checks, fallback behavior, and final report so the prompt describes a complete run.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Designing the core instructions for a new agent
  • Auditing a prompt before saving it
  • Defining behavior when tools or permissions are missing
mastra-ai/mastra2.9만2026년 10월 18일 업데이트

Create a dedicated test project linked to the current worktree and check Agent Builder through APIs and browser interactions. It covers agent and skill management, permissions, defaults, and related features, with selectable test sections.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Validate an Agent Builder feature branch before review
  • Check role-based permissions and authentication
  • Test agent and skill management through APIs and the UI
mastra-ai/mastra2.9만2026년 10월 18일 업데이트

Reviews pull requests for bugs, error handling, code quality, and style consistency. Organizes feedback into an overview, must-fix issues with file locations, improvement suggestions, and positive notes so reviewers can distinguish urgent problems from refinements.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Finding bugs that must be fixed before merging
  • Reviewing TypeScript types and asynchronous code
  • Checking naming, imports, and leftover debug statements
mastra-ai/mastra2.9만2026년 10월 18일 업데이트

Design instructions for agents that write, fix, review, or refactor code. Define behavior based on file access, select suitable tools, and set clear verification and completion rules for repository changes or copyable code output.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Designing an agent for repository bug fixes
  • Defining a pull request review agent
  • Creating a code generator without workspace access
mastra-ai/mastra2.9만2026년 10월 18일 업데이트

Configure Factory board behavior and GitHub or Linear event handlers in deployment code. Adjust stage transitions, phase meanings, and tool-result handling, then check the changes with focused tests and versioned audit records.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Add approval requirements to board transitions
  • Change GitHub or Linear event handling
  • Define custom board phases and tool-result rules
mastra-ai/mastra2.9만2026년 10월 18일 업데이트

Design agents that draft blog posts, social posts, newsletters, and marketing copy. Define the audience, brand voice, length, and required output so each agent delivers a complete draft with a headline and supporting notes.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Build a blog writing agent with a consistent brand voice
  • Design an agent for LinkedIn product posts
  • Define delivery rules for newsletter drafts
mastra-ai/mastra2.9만2026년 10월 18일 업데이트

mastra-ai의 스킬 모두 보기

이 스킬의 문제 신고