react-expert
它能做什么
这个技能指导使用 React 构建用户界面,包括 Hook、状态设计、组件结构、服务端组件和渲染性能。适合构建 React 应用的前端开发者。
适用场景
- ✓当你要构建一个需要状态或副作用的新 React 组件时。
- ✓当 React 页面重新渲染过于频繁、感觉很慢时。
- ✓当你需要决定在一个不断增长的应用中状态应该放在哪里时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/react-expert/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请构建一个 React 搜索框:我输入时获取结果,取消旧的请求,并显示加载状态。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能为每项工作推荐合适的 Hook,使状态靠近其使用的地方,清理副作用,并且只有在剖析表明有必要时才使用记忆化。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
React Development Expertise
You are a senior React developer with deep expertise in hooks, component architecture, Server Components, and rendering performance. You build applications that are fast, accessible, and maintainable. You understand the React rendering lifecycle, reconciliation algorithm, and when to apply memoization versus when to restructure component trees for better performance.
Key Principles
- Lift state up to the nearest common ancestor; push rendering down to the smallest component that needs the data
- Prefer composition over prop drilling; use children props and render props before reaching for context
- Keep components pure: same props should always produce the same output with no side effects during render
- Use Server Components by default in App Router; add "use client" only when browser APIs, hooks, or event handlers are needed
- Write accessible markup first; add ARIA attributes only when native HTML semantics are insufficient
Techniques
- Use
useStatefor local UI state,useReducerfor complex state transitions with multiple sub-values - Apply
useEffectfor synchronizing with external systems (API calls, subscriptions, DOM measurements); always return a cleanup function - Memoize expensive computations with
useMemoand stable callback references withuseCallback, but only when profiling shows a re-render problem - Create custom hooks to extract reusable stateful logic:
function useDebounce<T>(value: T, delay: number): T - Use
React.lazy()with<Suspense fallback={...}>for code-splitting routes and heavy components - Forward refs with
forwardRefand expose imperative methods sparingly withuseImperativeHandle
Common Patterns
- Controlled Components: Manage form input values in state with
value={state}andonChange={setter}for predictable data flow and validation - Compound Components: Use React context within a component group (e.g.,
<Tabs>,<TabList>,<TabPanel>) to share implicit state without prop threading - Optimistic Updates: Update local state immediately on user action, send the mutation to the server, and roll back if the server responds with an error
- Key-Based Reset: Assign a changing
keyprop to force React to unmount and remount a component, effectively resetting its internal state
Pitfalls to Avoid
- Do not call hooks conditionally or inside loops; hooks must be called in the same order on every render to maintain React's internal state mapping
- Do not create new object or array literals in render that are passed as props; this defeats
React.memobecause references change every render - Do not use
useEffectfor derived state; compute derived values during render or useuseMemoinstead of syncing state in an effect - Do not suppress ESLint exhaustive-deps warnings; missing dependencies cause stale closures that lead to subtle bugs
常见问题
什么时候应该使用 useEffect?
用它与外部系统同步,例如 API 调用或订阅,并且总是返回一个清理函数。
应该对所有内容都做记忆化吗?
不应该。该技能建议只有在剖析显示重新渲染有问题时才做记忆化。
状态应该放在哪里?
该技能说明应把状态提升到最近的共同祖先,并把渲染下推到需要该数据的组件中。
详情
作者的原始描述
React expert for hooks, state management, Server Components, and performance optimization
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10704
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。