← 返回
未分类 中文

React Patterns

Deep React patterns workflow—component boundaries, composition, hooks rules, effects and data fetching, performance (memo, lists, suspense), testing, and acc...
深度React模式工作流——组件边界、组合模式、Hooks规则、副作用与数据请求、性能优化(memo、列表、Suspense)、测试及无障碍访问
codekungfu codekungfu 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 631
下载
💾 4
安装
1
版本
#latest

概述

React Patterns (Deep Workflow)

Healthy React codebases emphasize clear data flow, minimal effects, and predictable rendering. Prefer composition over inheritance; treat effects as synchronization, not “do something after render” for everything.

When to Offer This Workflow

Trigger conditions:

  • Prop drilling vs context vs external stores; confusion on server components (Next) vs client
  • useEffect spaghetti; stale closures; double-fetch
  • Re-render performance; large lists; hydration issues

Initial offer:

Use six stages: (1) structure & boundaries, (2) state & data sources, (3) hooks discipline, (4) effects & events, (5) performance, (6) testing & a11y). Confirm React version and framework (plain CRA, Vite, Next App Router).


Stage 1: Structure & Boundaries

Goal: Colocate state; split presentational vs container only when it clarifies—not by default.

Practices

  • Compound components for flexible APIs; avoid mega-props objects
  • In Next App Router: default to Server Components; add use client at leaves

Stage 2: State & Data Sources

Goal: Local state for UI; server state via React Query/SWR/Apollo as appropriate; avoid duplicating server entities in global stores without sync rules.


Stage 3: Hooks Discipline

Goal: Rules of Hooks satisfied; custom hooks encapsulate reusable stateful logic with clear inputs/outputs.

Practices

  • Name hooks useThing; return stable APIs (objects memoized when needed)

Stage 4: Effects & Events

Goal: Prefer event handlers for user-driven work; useEffect for sync with external systems (subscriptions, non-React widgets).

Practices

  • Cleanup subscriptions; abort fetches; list effect dependencies honestly
  • Strict Mode double-invoke in dev—write effects idempotent

Stage 5: Performance

Goal: Measure before memo; virtualize long lists; code-split routes.

Practices

  • useCallback/useMemo when profiling shows benefit—not by default
  • Concurrent features and Suspense boundaries where supported

Stage 6: Testing & Accessibility

Goal: React Testing Library user-centric queries; focus management and labels for forms.


Final Review Checklist

  • [ ] Component boundaries match data ownership
  • [ ] Server vs client state strategy clear
  • [ ] Hooks and effects used appropriately
  • [ ] Performance optimizations evidence-based
  • [ ] Tests and a11y basics covered for critical flows

Tips for Effective Guidance

  • Derive state when possible instead of storing redundant pieces.
  • URL as state for shareable UI state when appropriate.
  • Point to state-management skill for Redux/Zustand-scale decisions.

Handling Deviations

  • Legacy class components: same principles; hooks migration incremental.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 04:47 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 198 📥 68,226
business-ops

抖音电商

codekungfu
该技能介绍如何通过抖音电商实现变现;当你计划从事或优化抖音电商时调用。
★ 2 📥 1,981
dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 42,112