New advertisers: 50% off your first month with code FIRSTMONTHSee slots
github avatar

React18 Batching Patterns

Diagnoses and fixes React 18 automatic batching regressions in class components, with a flushSync decision tree.

skills.sh installs
757
GitHub stars
41.4K
last updated
Aug 21, 2026
View on GitHub

What it does

  • Covers setState calls in async methods, setTimeout, Promise .then()/.catch(), and native event handlers, comparing React 17 and React 18 behavior
  • Includes three fix categories (A, B, C) with before and after code in references/batching-categories.md and references/flushSync-guide.md
  • Enforces a diagnosis step first: code reading this.state after await is classified as a silent state-read bug before any fix is chosen
  • Designed for teams upgrading class-component codebases to React 18, including fixing test failures from intermediate state assertions

Install

$ npx -y skills add github/awesome-copilot --skill react18-batching-patterns -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

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 setStateReact 17React 18
React event handlerBatchedBatched (same)
setTimeoutImmediate re-renderBatched
Promise .then() / .catch()Immediate re-renderBatched
async/awaitImmediate re-renderBatched
Native addEventListener callbackImmediate re-renderBatched

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)

Details

Repository
github.com/github/awesome-copilot
Categories
Frontend & UI Code, Debugging
First seen
May 16, 2026

More from github/awesome-copilot

All 293

Similar to React18 Batching Patterns

More Frontend & UI Code