返回顶部
r

react-patterns

Deep React patterns workflow—component boundaries, composition, hooks rules, effects and data fetching, performance (memo, lists, suspense), testing, and accessibility. Use when structuring React apps, reviewing component design, or debugging re-renders.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
217
下载量
0
收藏
概述
安装方式
版本历史

react-patterns

# 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.

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 react-patterns-1776028928 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 react-patterns-1776028928 技能

通过命令行安装

skillhub install react-patterns-1776028928

下载 Zip 包

⬇ 下载 react-patterns v1.0.0

文件大小: 2.19 KB | 发布时间: 2026-4-13 11:44

v1.0.0 最新 2026-4-13 11:44
- Initial release of the skill.
- Provides a structured, 6-stage workflow for React patterns: component boundaries, state, hooks, effects, performance, and testing/accessibility.
- Offers concise guidance for common challenges: prop drilling, useEffect, re-renders, and hydration.
- Includes practical tips and a review checklist for React apps.
- Guidance adapts to different frameworks and React versions.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部