跳到正文
cccskills
免费在 GitHub 公开

react

React Rules of React — strict adherence required for React Compiler compatibility. Covers purity, idempotency, immutability, hook call rules, and component rendering rules. Use when writing any React component, custom hook, or reviewing React code.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(5)

  • SKILL.md4.7 KB
  • components-and-hooks-must-be-pure.md17.1 KB
  • index.md4.2 KB
  • react-calls-components-and-hooks.md4.8 KB
  • rules-of-hooks.md3.9 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Purpose

Enforce the Rules of React so that React Compiler can automatically memoize components and hooks at build time, eliminating the need for manual useMemo/useCallback/React.memo. Violations of these rules cause incorrect memoization and subtle bugs.

When this skill applies

  • Writing or reviewing any React function component or custom hook
  • Debugging unexpected re-renders, stale state, or memoization problems
  • Evaluating whether code is React Compiler-compatible
  • Any time you see use client, useState, useEffect, useMemo, useCallback, or custom use* hooks

The Three Pillars (read the detail files)

PillarFileKey concern
Components and Hooks must be purecomponents-and-hooks-must-be-pure.mdIdempotency, no side effects in render, immutability
React calls Components and Hooksreact-calls-components-and-hooks.mdNever call components directly, never pass hooks as values
Rules of Hooksrules-of-hooks.mdTop-level only, React functions only
Overview / indexindex.mdSummary of all rules with links to sections

Critical rules — enforce these without exception

Purity

  • Components and hooks must be idempotent. Same inputs (props, state, context, args) → same output, every time. new Date(), Math.random(), and any non-deterministic calls must live in useEffect or event handlers — never in render.
  • No side effects in render. DOM writes (document.title = …), network calls, subscriptions, and logging must not happen at the top level of a component function. Use useEffect or event handlers.
  • Local mutation is fine. Creating and mutating a local array or object within a single render call is allowed — it never escapes the render scope.

Immutability

  • Never mutate props. Derive a new value instead: const url = new Url(item.url, base) not item.url = ….
  • Never mutate state directly. Always use the setter from useState. Mutating the state variable does not trigger a re-render.
  • Never mutate hook arguments or return values. Spread ({ ...icon }) before modifying. Hook internals may memoize based on reference identity — mutating breaks that.
  • Never mutate values after passing them to JSX. Create separate objects for each consumer before the JSX expression that uses them.

React controls rendering

  • Never call component functions directly. <Article /> yes, Article() no. Direct calls bypass React's reconciler, break hook rules, and prevent optimizations.
  • Never pass hooks as values. No higher-order hooks (withLogging(useData)), no hook props (<Button useData={hook} />). Hooks are always called inline and statically.
  • Hooks must be static. The set of hooks a component calls must be the same on every render — no conditional hook creation.

Rules of Hooks (call-site rules)

  • Top level only. Never inside if, for, while, nested functions, event handlers, try/catch/finally, useMemo, useReducer, or useEffect callbacks.
  • React functions only. Only call hooks from function components or custom hooks (functions whose name starts with use). Never from plain JS functions, class components, or utilities.
  • After a conditional early return — move any hook call before the return.

React Compiler compatibility checklist

Before marking code as done, verify:

  • No new Date() / Math.random() in render body
  • No prop or state mutation
  • No DOM side effects at top level
  • All hooks called unconditionally at top level
  • Components only used as JSX, never called as functions
  • No hook passed as a prop or stored in a variable then called later
  • Hook arguments not mutated after being passed
  • Values not mutated after being passed to JSX

If any item fails, fix the violation rather than adding a // eslint-disable or "use no memo" directive. Reserve "use no memo" only for third-party code you cannot change.


ESLint enforcement

Install eslint-plugin-react-hooks and enable:

{
  "rules": {
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn"
  }
}

Use React's Strict Mode (<StrictMode>) in development — it double-invokes render to surface impure components.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

astro

免费

Reference for Astro — the core web framework the gatOS docs site (under site/) is built on. Use this when authoring or editing pages in site/, working with .astro/.md/.mdx files, content collections, the astro.config.mjs, or component/JSX-in-Markdown mechanics. Covers Astro component anatomy, using components in MDX, content collections, frontmatter, imports, expressions, and the build/dev commands — enough to work the site without leaving the repo. Pair with the `starlight` skill (the docs theme + its components) and the `tutorials` skill (the gatOS house style).

中文简介正在准备中。当前显示原文说明。

meow-sci/gatOS132026年10月11日 更新

bun

免费

how to use bun effectively for scripting and sqlite and more

中文简介正在准备中。当前显示原文说明。

meow-sci/gatOS132026年10月11日 更新

gatos

免费

Write scripts and programs against gatOS — the KSA mod that exposes live Kitten Space Agency simulation state as a 9P filesystem at /sim (also over HTTP /v1, MQTT, and an AI-oriented MCP server). Use this when asked to read game/celestial/vehicle telemetry, control vehicles (throttle, ignite, staging, attitude, burns, RCS, lights, docking), use game/debug controls (teleport, impulse kick, refuel, time-warp, switch vessel), direct the in-game camera / author cinematic shots and tracks, schedule timed command sequences, or write flight-computer / autopilot programs. Covers the full /sim catalog, the command model, KSA coordinate frames, and worked Bun/TypeScript + Rust examples.

中文简介正在准备中。当前显示原文说明。

meow-sci/gatOS132026年10月11日 更新

harmony

免费

Expert in use of Harmony Lib for runtime patching of dotnet C# code

中文简介正在准备中。当前显示原文说明。

meow-sci/gatOS132026年10月11日 更新

imgui

免费

ImGui is an immediate mode UI library. KSA uses ImGui for UI

中文简介正在准备中。当前显示原文说明。

meow-sci/gatOS132026年10月11日 更新

ksa

免费

detailed information about kitten space agency (KSA) game code, decompiled sources, modding patterns, architecture and best practices for working with mods and the game codebase

中文简介正在准备中。当前显示原文说明。

meow-sci/gatOS132026年10月11日 更新

查看 meow-sci 的全部技能

报告此技能的问题