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

react18-lifecycle-patterns

Qué hace

Te ayuda a actualizar los métodos de ciclo de vida ('lifecycle') antiguos del código de React a versiones más recientes. Te muestra cómo mover las partes del código a los lugares correctos para que funcionen bien con las versiones nuevas de React.

Cuándo usarla

  • ✓Cuando tu código de React usa métodos de ciclo de vida que ya no se recomiendan.
  • ✓Cuando tienes que decidir si usar 'getDerivedStateFromProps' o 'componentDidUpdate'.
  • ✓Cuando necesitas añadir 'getSnapshotBeforeUpdate' para gestionar las actualizaciones.

Link de la skill

https://github.com/github/awesome-copilot/blob/main/skills/react18-lifecycle-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-lifecycle-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 migro el método 'componentWillMount' que establece el estado inicial de mi componente de React?”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

Esta guía compara lo que hace un método antiguo con las nuevas formas de hacer lo mismo en React 18. Según la función del método antiguo, te dirige a ejemplos específicos.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

React 18 Lifecycle Patterns

Reference for migrating the three unsafe class component lifecycle methods to React 18.3.1 compliant patterns.

Quick Decision Guide

Before migrating any lifecycle method, identify the semantic category of what the method does. Wrong category = wrong migration. The table below routes you to the correct reference file.

componentWillMount - what does it do?

What it does Correct migration Reference
Sets initial state (this.setState(...)) Move to constructor → componentWillMount.md
Runs a side effect (fetch, subscription, DOM) Move to componentDidMount → componentWillMount.md
Derives initial state from props Move to constructor with props → componentWillMount.md

componentWillReceiveProps - what does it do?

What it does Correct migration Reference
Async side effect triggered by prop change (fetch, cancel) componentDidUpdate → componentWillReceiveProps.md
Pure state derivation from new props (no side effects) getDerivedStateFromProps → componentWillReceiveProps.md

componentWillUpdate - what does it do?

What it does Correct migration Reference
Reads the DOM before update (scroll, size, position) getSnapshotBeforeUpdate → componentWillUpdate.md
Cancels requests / runs effects before update componentDidUpdate with prev comparison → componentWillUpdate.md

The UNSAFE_ Prefix Rule

Never use UNSAFE_componentWillMount, UNSAFE_componentWillReceiveProps, or UNSAFE_componentWillUpdate as a permanent fix.

Prefixing suppresses the React 18.3.1 warning but does NOT:

  • Fix concurrent mode safety issues
  • Prepare the codebase for React 19 (where these are removed, with or without the prefix)
  • Fix the underlying semantic problem the migration is meant to address

The UNSAFE_ prefix is only appropriate as a temporary hold while scheduling the real migration sprint. Mark any UNSAFE_ prefix additions with:

// TODO: React 19 will remove this. Migrate before React 19 upgrade.
// UNSAFE_ prefix added temporarily - replace with componentDidMount / getDerivedStateFromProps / etc.

Reference Files

Read the full reference file for the lifecycle method you are migrating:

  • references/componentWillMount.md - 3 cases with full before/after code
  • references/componentWillReceiveProps.md - getDerivedStateFromProps trap warnings, full examples
  • references/componentWillUpdate.md - getSnapshotBeforeUpdate + componentDidUpdate pairing

Read the relevant file before writing any migration code.

Preguntas frecuentes

¿Qué son los 'métodos de ciclo de vida'?

Son funciones especiales de los componentes de React que se ejecutan en momentos concretos, como cuando el componente se crea, se actualiza o se elimina.

¿Por qué no puedo usar simplemente los métodos antiguos como 'UNSAFE_componentWillMount'?

El prefijo 'UNSAFE_' solo oculta una advertencia, pero no soluciona los problemas de compatibilidad con las versiones nuevas de React. Es una solución temporal, no definitiva.

¿Dónde encuentro los ejemplos de código para la migración?

Los ejemplos detallados están en archivos de referencia separados, como 'componentWillMount.md', 'componentWillReceiveProps.md' y 'componentWillUpdate.md', a los que te dirige la guía.

Detalles

Descripción original del autor

Provides exact before/after migration patterns for the three unsafe class component lifecycle methods - componentWillMount, componentWillReceiveProps, and componentWillUpdate - targeting React 18.3.1. Use this skill whenever a class component needs its lifecycle methods migrated, when deciding between getDerivedStateFromProps vs componentDidUpdate, when adding getSnapshotBeforeUpdate, or when fixi

repo: github/awesome-copilot

Popularidad

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

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas