跳到正文
Skillpedia
网站与界面(前端)18k · #10704

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/react-expert/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 useState for local UI state, useReducer for complex state transitions with multiple sub-values
  • Apply useEffect for synchronizing with external systems (API calls, subscriptions, DOM measurements); always return a cleanup function
  • Memoize expensive computations with useMemo and stable callback references with useCallback, 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 forwardRef and expose imperative methods sparingly with useImperativeHandle

Common Patterns

  • Controlled Components: Manage form input values in state with value={state} and onChange={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 key prop 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.memo because references change every render
  • Do not use useEffect for derived state; compute derived values during render or use useMemo instead 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能