Saltar al contenido
Skillpedia
Sitios e interfaces (frontend)40 mil · #7383

react18-batching-patterns

Qué hace

Esta herramienta ayuda a corregir un problema habitual en código antiguo que usa 'componentes de clase' con React 18. Hace que las actualizaciones de pantalla se produzcan juntas en lugar de por separado, lo que mejora el rendimiento.

Cuándo usarla

  • ✓Cuando tienes varias actualizaciones de pantalla que no aparecen todas a la vez.
  • ✓Si tu código actualiza el estado varias veces dentro de funciones asíncronas (async/await, Promises, setTimeout).
  • ✓Si notas problemas de rendimiento o errores visuales después de actualizar a React 18.

Link de la skill

https://github.com/github/awesome-copilot/blob/main/skills/react18-batching-patterns/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/github/awesome-copilot/blob/main/skills/react18-batching-patterns/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“¿Cómo hago que las actualizaciones de pantalla de mi componente de clase funcionen bien con React 18?”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

Analiza dónde llamas a las actualizaciones de pantalla (setState) en tu código. Si están en lugares donde React 18 ya las agrupa automáticamente (como dentro de eventos), te sugiere cómo arreglarlo. Si no, te ayuda a decidir si forzar una actualización inmediata (flushSync) o reestructurar el código.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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.

Preguntas frecuentes

¿Qué es el 'batching'?

El 'batching' es cuando React agrupa varias actualizaciones de pantalla en una sola, para que la interfaz no tenga que redibujarse varias veces. Así mejora el rendimiento.

¿Qué cambió en React 18?

En React 18, el 'batching' (agrupar actualizaciones) empezó a funcionar automáticamente en más lugares, como dentro de funciones asíncronas (setTimeout, Promises). Es algo bueno, pero puede romper código antiguo que dependía de actualizaciones inmediatas.

¿Cuándo debo usar `flushSync`?

Usa `flushSync` solo cuando sea imprescindible que el usuario vea una actualización inmediata en pantalla antes de que empiece una operación larga. En la mayoría de los casos, es mejor corregir el código (reestructurarlo) en lugar de usar `flushSync`.

Detalles

Descripción original del autor

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

Popularidad

Estrellas en GitHub
40 mil
Posición en el ranking
#7383
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas