본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)40k · #7383

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/react18-batching-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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 code
  • references/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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬