github avatar

React18 Batching Patterns

If you're migrating a class component codebase to React 18, this is your batching regression field guide. React 18 now batches setState calls inside setTimeout, promises, and async/await where React 17 didn't, which silently breaks code that reads this.state after an await to make decisions. The skill gives you a three category diagnostic tree and shows exactly when to use flushSync versus when to refactor. The real value is the flushSync discipline, it stops you from papering over batching issues with synchronous renders everywhere, which would kill the performance gains you upgraded for. Includes a comparison table and concrete before/after patterns for each scenario.

skills.sh installs
756
GitHub stars
41K
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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)

Sponsors

Details

Repository
github.com/github/awesome-copilot
Categories
Frontend Development, Testing & QA, Git & Pull Requests, Documentation, AI & Agent Building, Productivity & Planning
First seen
May 16, 2026

More from github/awesome-copilot

All 318
1mblode avatarscaffold-climblode/agent-skillsScaffolds a production-ready TypeScript CLI and npm package with ESM, a dual tsdown build (CLI binary plus typed library), vitest, oxlint and oxfmt via ultracit751skills.sh installs
2mindrally avatarsveltekitmindrally/skillsExpert guidance for SvelteKit development with TypeScript, Tailwind CSS, SSR/SSG, and performance optimization best practices749skills.sh installs
3skills-il avatarhebrew-rtl-best-practicesskills-il/localizationImplement right-to-left (RTL) layouts for Hebrew web applications. Use when user asks about RTL layout, Hebrew text direction, bidirectional (bidi) text, Hebrew746skills.sh installs
4github avatarreact18-lifecycle-patternsgithub/awesome-copilotProvides exact before/after migration patterns for the three unsafe class component lifecycle methods - componentWillMount, componentWillReceiveProps, and compo745skills.sh installs
5github avatarreact18-string-refsgithub/awesome-copilotProvides exact migration patterns for React string refs (ref="name" + this.refs.name) to React.createRef() in class components. Use this skill whenever migratin743skills.sh installs
621st-dev avataragent-elements21st-dev/agent-elementsUse whenever the user wants to build or modify a chat, agent, or tool-calling UI in a React 19 + Tailwind v4 project — especially if the code imports from `@/co733skills.sh installs