react
React 编码风格和最佳实践。
📖 中文导读:React 编码风格和最佳实践。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: react description: React coding style and best practices. pattern: .(jsx|tsx)(\s|$)
- Use
toast.error(error.message)in catch blocks. Noconsole.errorallowed! - Minimal DOM nesting. Use
<Fragment>or<>instead of useless<div>wrappers - Modern React 19+ patterns only (e.g.
usefor promises/context, Server Actions,useFormStatus) - Boolean props shorthand:
<Component prop />not<Component prop={true} /> - Component names in PascalCase, props in camelCase
- Logic first: Define hooks/state at the top, then return JSX. Keep components lean
- Prefer
onChangeoveruseEffectfor syncing state whenever possible - Map directly on components/fragments, don't wrap
items.mapin a stray<div> - Avoid
useCallback/useMemounless it's actually heavy. React is fast enough, don't be extra