react18-batching-patterns
What it does
This tool helps fix a common issue in older code ('class components') using React 18. It ensures screen updates happen together instead of separately, improving performance.
When to use it
- ✓When you have multiple screen updates that don't appear all at once.
- ✓If your code updates the state multiple times within asynchronous functions (async/await, Promises, setTimeout).
- ✓If you're experiencing performance issues or visual bugs after updating to React 18.
Skill link
https://github.com/github/awesome-copilot/blob/main/skills/react18-batching-patterns/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“How can I make my class component's screen updates work correctly with React 18?”
5 new skills a week. 1 minute to read.
How it works
It analyzes where you call screen updates (setState) in your code. If they are in places React 18 automatically batches (like inside events), it suggests how to fix it. If not, it helps decide whether to force an immediate update (flushSync) or refactor the code.
Technical content (original SKILL.md)
Original text by the author, straight from 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.
FAQ
What is 'batching'?
'Batching' is when React groups multiple screen updates into one so the user interface doesn't have to redraw multiple times, which improves performance.
What changed in React 18?
In React 18, 'batching' (grouping updates) started working automatically in more places, like inside asynchronous functions (setTimeout, Promises). This is good, but can break older code that relied on immediate updates.
When should I use `flushSync`?
Use `flushSync` only when it's essential for the user to see an immediate screen update before a long operation begins. In most cases, it's better to fix the code ('refactor') instead of using `flushSync`.
Details
Original description by the author
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
Popularity
- GitHub stars
- 40k
- Ranking position
- #7383
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
acquire-codebase-knowledge
40kHelps your agent understand and document an existing code project. It's useful for onboarding new people or getting an overview of the architecture.
acreadiness-assess
40kEnables your agent to assess a project's readiness for AI and generate a report. It's useful for understanding how well a project is prepared to use AI tools.
acreadiness-generate-instructions
40kHelps your agent create instructions for AI tools based on an assessment. It's useful for improving how AI interacts with code and closing identified gaps.
acreadiness-policy
40kEnables your agent to help define or apply policies for AI project assessment. It's useful for standardizing how projects are evaluated and ensuring compliance.
Similar skills
angular-developer
280kHelps your agent create Angular code and give project structure advice. Useful for starting new projects, creating code parts, or improving performance and accessibility.
frontend-a11y
280kHelps your agent make web interfaces accessible to everyone. It ensures websites and apps work well with screen readers and keyboard navigation.
frontend-patterns
280kHas your agent apply modern patterns in frontend development. It optimizes performance, manages state, and follows best practices in React and Next.js.