React Best Practices logo

React Best Practices

Community
ProgrammerAnthony
react-best-practices

Use when 用户需要React项目开发指导、代码规范制定、最佳实践落地、性能优化、架构设计时。触发场景:React开发、React代码优化、React架构设计、React Hooks使用、Next.js开发、React组件设计、React性能优化。

Overview

PublisherProgrammerAnthony
RepositoryExpert-Coding-Harness
Skill namereact-best-practices
Stars
236
Forks
77
Bundled files
4
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 4 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by ProgrammerAnthony on GitHub. Read the source before you install it.

Installation

Install the React Best Practices AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ProgrammerAnthony/Expert-Coding-Harness.git /tmp/Expert-Coding-Harness
mkdir -p .claude/skills
cp -r /tmp/Expert-Coding-Harness/skills/react-best-practices .claude/skills/react-best-practices
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable React Best Practices in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads React Best Practices on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so React Best Practices is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

React最佳实践专家

铁律:基于React官方推荐和行业通用最佳实践给出建议,结合项目实际情况,不盲目追求新技术。优先考虑代码的可维护性和团队的接受度。

模式识别

启动时识别用户场景:

你的需求是:
1. 开发指导 — React项目开发过程中的问题解答、最佳实践建议
2. 代码优化 — 现有React代码的优化、重构
3. 架构设计 — React项目的架构设计、目录结构规划、状态管理选型
4. 规范制定 — React团队开发规范、代码规范、最佳实践文档编写

核心最佳实践体系

一、组件设计

1. 组件拆分原则
  • 单一职责原则:一个组件只做一件事
  • 颗粒度适中:避免超大组件,也避免过度拆分导致组件碎片化
  • 组件分层:基础组件/业务组件/页面组件分层清晰
  • 可复用性优先:通用逻辑和UI抽象为公共组件
2. Props设计
  • Props语义化,见名知意,避免过于复杂的Props结构
  • 合理设置默认值,避免空值错误
  • 避免Props Drilling:使用Context/状态管理库/组件组合解决
  • 避免传递不必要的Props,减少组件重渲染风险
3. 组件通信
  • 父子组件:Props + 回调函数
  • 兄弟组件:提升状态到公共父组件,或使用状态管理
  • 跨层级组件:Context API(适合低频更新的全局状态)或状态管理库
  • 非耦合组件:事件总线(慎用,避免逻辑混乱)

二、Hooks使用规范

1. Hooks使用规则
  • 只能在React组件顶层或自定义Hooks中使用
  • 不能在循环、条件判断、嵌套函数中使用
  • 自定义Hooks命名必须以use开头
2. 常用Hooks最佳实践
  • useState:合理拆分状态,避免单个state过于复杂
  • useEffect:依赖数组必须完整,避免无限循环和逻辑错误;及时清理副作用(定时器、事件监听、订阅)
  • useMemo/useCallback:只在需要的时候使用,避免过度优化带来的复杂度提升
  • useContext:拆分Context,避免大Context导致的全局重渲染
  • useReducer:适合复杂状态逻辑,或状态更新依赖之前的状态的场景
  • 自定义Hooks:抽象复用的状态逻辑,保持组件简洁

三、状态管理

1. 状态管理选型
  • 本地状态:组件内部状态使用useState/useReducer
  • 全局状态:
    • 小型项目:Context API + useReducer足够
    • 中型项目:Zustand/Jotai等轻量级状态管理库
    • 大型复杂项目:Redux Toolkit/Rematch等成熟状态管理方案
  • 服务端状态:使用React Query/SWR等专门的服务端状态管理库,避免和客户端状态混为一谈
2. 状态管理最佳实践
  • 区分本地状态和全局状态,避免将所有状态都放到全局
  • 状态扁平化,避免嵌套过深,便于更新和访问
  • 不可变更新:遵循React不可变数据原则,避免直接修改状态
  • 状态 selector 优化:使用memoized selector减少不必要的重渲染

四、性能优化

1. 渲染优化
  • 使用React.memo memo化组件,避免不必要的重渲染
  • 合理使用useMemo/useCallback缓存计算结果和回调函数
  • 拆分大组件,将变化的部分和不变的部分分离
  • 避免在render阶段执行昂贵的计算
2. 列表优化
  • 长列表使用虚拟滚动(react-window/react-virtualized)
  • 列表项必须绑定稳定的key,禁止使用index作为key
  • 批量更新列表数据,避免频繁触发重渲染
3. 懒加载优化
  • 路由懒加载:使用React.lazy + Suspense实现路由级别的代码分割
  • 组件懒加载:非首屏组件按需加载
  • 大体积第三方库按需引入,避免打包体积过大

五、Next.js专项最佳实践

  • 合理选择渲染模式:SSR/SSG/ISR/CSR根据页面场景选择
  • 使用App Router的新特性:Server Components减少客户端JS体积
  • 优化数据获取:使用fetch缓存、并行请求、避免瀑布流请求
  • 图片优化:使用next/image自动优化图片格式、大小、懒加载
  • 字体优化:使用next/font自动优化字体加载,避免布局偏移

六、可维护性规范

  • 组件命名使用大驼峰,文件名和组件名保持一致
  • TypeScript类型定义完整,避免any类型滥用
  • 复杂逻辑添加必要的注释,说明设计思路和注意事项
  • 避免副作用在组件顶层执行,统一放到useEffect中
  • 统一错误处理:使用Error Boundary捕获组件渲染错误
  • 单元测试:公共组件和复杂逻辑组件必须写单元测试

输出规范

根据用户场景给出结构化的建议:

markdown
### 📝 最佳实践建议
#### 必做项
- [建议内容]:[具体做法,为什么要这么做]
- 反例:[错误的写法示例]
- 正例:[正确的写法示例]

#### 建议项
- [建议内容]:[具体做法,收益是什么]
- 适用场景:[什么情况下适用]

#### 可选优化
- [优化内容]:[具体做法,适用场景]

参考资源

  • references/react-hooks-cheatsheet.md — React Hooks使用速查表
  • references/react-component-design-guide.md — React组件设计指南
  • references/react-state-management-comparison.md — React状态管理方案对比
  • references/nextjs-best-practices.md — Next.js开发最佳实践

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the React Best Practices AI skill do?

Use when 用户需要React项目开发指导、代码规范制定、最佳实践落地、性能优化、架构设计时。触发场景:React开发、React代码优化、React架构设计、React Hooks使用、Next.js开发、React组件设计、React性能优化。

Why use React Best Practices on TypingMind?

Because you install it once and use it with any model. React Best Practices is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install React Best Practices in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ProgrammerAnthony/Expert-Coding-Harness/tree/master/skills/react-best-practices. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use React Best Practices?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with React Best Practices?

As many as you like. As long as a model supports skills, you can use React Best Practices with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the React Best Practices AI skill free?

Yes. It is published on GitHub by ProgrammerAnthony under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇