react18-batching-patterns
できること
このツールは、React 18 を使う際に、古いコード(「クラスコンポーネント」)でよく起きる問題の修正に役立ちます。画面の更新を別々ではなくまとめて行うようにし、パフォーマンスを改善します。
使う場面
- ✓複数の画面更新が、一度に表示されないとき。
- ✓非同期関数(async/await、Promise、setTimeout)の中で、状態を何度も更新しているとき。
- ✓React 18 にアップデートした後に、パフォーマンスの低下や表示の不具合が起きているとき。
スキルのリンク
https://github.com/github/awesome-copilot/blob/main/skills/react18-batching-patterns/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“React 18 でクラスコンポーネントの画面更新を正しく動かすにはどうすればよいですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
コードのどこで画面更新(setState)を呼び出しているかを分析します。React 18 が自動でまとめて処理する場所(イベント内など)であれば修正方法を提案します。そうでない場合は、即座に更新を強制する(flushSync)か、コードを書き直す(リファクタリング)かの判断を手伝います。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
React 18 Automatic Batching Patterns
Reference for diagnosing and fixing the most dangerous silent breaking change in React 18 for class-component codebases.
The Core Change
| Location of setState | React 17 | React 18 |
|---|---|---|
| React event handler | Batched | Batched (same) |
| setTimeout | Immediate re-render | Batched |
| Promise .then() / .catch() | Immediate re-render | Batched |
| async/await | Immediate re-render | Batched |
| Native addEventListener callback | Immediate re-render | Batched |
Batched means: all setState calls within that execution context flush together in a single re-render at the end. No intermediate renders occur.
Quick Diagnosis
Read every async class method. Ask: does any code after an await read this.state to make a decision?
Code reads this.state after await?
YES → Category A (silent state-read bug)
NO, but intermediate render must be visible to user?
YES → Category C (flushSync needed)
NO → Category B (refactor, no flushSync)
For the full pattern for each category, read:
references/batching-categories.md- Category A, B, C with full before/after codereferences/flushSync-guide.md- when to use flushSync, when NOT to, import syntax
The flushSync Rule
Use flushSync sparingly. It forces a synchronous re-render, bypassing React 18's concurrent scheduler. Overusing it negates the performance benefits of React 18.
Only use flushSync when:
- The user must see an intermediate UI state before an async operation begins
- A spinner/loading state must render before a fetch starts
- Sequential UI steps have distinct visible states (progress wizard, multi-step flow)
In most cases, the fix is a refactor - restructuring the code to not read this.state after await. Read references/batching-categories.md for the correct approach per category.
よくある質問
「バッチング」とは何ですか?
React が複数の画面更新を一つにまとめて処理することです。ユーザーインターフェースの再描画が何度も起きないようにするため、パフォーマンスが向上します。
React 18 では何が変わりましたか?
React 18 では、setTimeout や Promise などの非同期関数の中でも、バッチングが自動で働くようになりました。これは良いことですが、即座の更新を前提とした古いコードでは動作が変わることがあります。
`flushSync` はいつ使うべきですか?
長い処理が始まる前に、ユーザーが即座に画面の更新を見る必要がある場合にだけ使ってください。多くの場合は、`flushSync` を使うより、コードを書き直す(リファクタリング)方が望ましいです。
詳細
作者による元の説明
Provides exact patterns for diagnosing and fixing automatic batching regressions in React 18 class components. Use this skill whenever a class component has multiple setState calls in an async method, inside setTimeout, inside a Promise .then() or .catch(), or in a native event handler. Use it before writing any flushSync call - the decision tree here prevents unnecessary flushSync overuse. Also u
repo: github/awesome-copilot
人気
- GitHubのスター
- 40k
- ランキング
- #7383
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
acquire-codebase-knowledge
40kエージェントが、既存のコードプロジェクトを理解してドキュメント化できるよう支援します。新しく参加するメンバーのオンボーディングや、アーキテクチャの全体像の把握に役立ちます。
acreadiness-assess
40kエージェントが、プロジェクトのAI対応状況を評価してレポートを生成できるよう支援します。プロジェクトがAIツールをどの程度活用できる状態にあるかを把握するのに役立ちます。
acreadiness-generate-instructions
40kエージェントが、評価結果をもとにAIツール向けの指示文を作成できるよう支援します。AIがコードとどのようにやり取りするかを改善し、特定された不足点を解消するのに役立ちます。
acreadiness-policy
40kエージェントが、AIプロジェクトの評価ポリシーの策定や適用を支援できるようにします。プロジェクトの評価方法を標準化し、コンプライアンスを確保するのに役立ちます。
似ているスキル
angular-developer
280kエージェントがAngularのコードを作成し、プロジェクト構成についてアドバイスできるようにします。新しいプロジェクトの開始、コード部品の作成、パフォーマンスやアクセシビリティの改善に役立ちます。
frontend-a11y
280kエージェントが Web インターフェースを誰にとっても使いやすくするよう支援します。スクリーンリーダーやキーボード操作に対応し、サイトやアプリが適切に動作するようにします。
frontend-patterns
280kエージェントがフロントエンド開発の最新パターンを適用できるようにします。React と Next.js において、パフォーマンスの最適化、状態管理、ベストプラクティスの遵守を行います。