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.
자주 묻는 질문
'batching'은 무엇인가요?
React가 여러 화면 업데이트를 하나로 묶어, 사용자 인터페이스가 여러 번 다시 그려지지 않도록 하는 것입니다. 성능을 개선합니다.
React 18에서 무엇이 바뀌었나요?
React 18에서는 batching(업데이트 묶기)이 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모든 사람이 웹 인터페이스를 쓸 수 있도록 에이전트를 돕습니다. 웹사이트와 앱이 화면 읽기 프로그램과 키보드 탐색에서 잘 작동하도록 합니다.
frontend-patterns
280k프론트엔드 개발의 현대적인 패턴을 적용하도록 에이전트를 돕습니다. React와 Next.js에서 성능을 최적화하고, 상태를 관리하며, 모범 사례를 따릅니다.