Index of every page on this site: llms.txt
All skills
github avatar

/react18-lifecycle-patterns

@f10fdb8 official
by githubgithub/awesome-copilot42k stars
5,426
Run it yourself

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 fixing React 18 UNSAFE_ lifecycle warnings. Always use this skill before writing any lifecycle migration code - do not guess the pattern from memory, the decision trees here prevent the most common migration mistakes.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/react18-lifecycle-patterns

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈160 tokens for metadata: the name and description. ≈746 when used: this file. ≈3.4k more on demand in 3 files.

Description uses 8.0% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈642 characters, or 8.0%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

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.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo4 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides safe documentation and code examples for migrating React lifecycle methods. No security issues were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f10fdb8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 7 months ago
  • React
  • react18
  • lifecycle
  • class-components
  • migration
  • componentwillmount
  • componentwillreceiveprops
  • componentwillupdate
  • getderivedstatefromprops
  • getsnapshotbeforeupdate

README badge

README badge for github/awesome-copilot/react18-lifecycle-patterns

Provides decision trees and before/after code patterns for migrating React class component lifecycle methods (componentWillMount, componentWillReceiveProps, componentWillUpdate) to React 18.3.1 compliant equivalents. Targets the three unsafe lifecycle methods specifically and routes each to the correct replacement (constructor, componentDidMount, getDerivedStateFromProps, getSnapshotBeforeUpdate, or componentDidUpdate) based on whether the code performs side effects or derives state.

Generated from the current SKILL.md.

Does this skill cover all three unsafe lifecycle methods?
Yes. It provides migration patterns for componentWillMount, componentWillReceiveProps, and componentWillUpdate, with decision trees to route each to the correct replacement (constructor, componentDidMount, getDerivedStateFromProps, getSnapshotBeforeUpdate, or componentDidUpdate).
Can I just add the UNSAFE_ prefix to suppress warnings?
No. The skill explicitly warns that UNSAFE_ prefixes suppress warnings but do not fix concurrent mode safety issues or prepare code for React 19, where these methods are removed entirely. Real migration is required.
How do I know which migration pattern to use?
The skill provides a semantic decision guide—you identify what the lifecycle method does (e.g. sets initial state, runs async side effects, reads the DOM) and the table routes you to the correct replacement and reference file.
Does this target a specific React version?
Yes, React 18.3.1. The patterns account for concurrent mode and React 18 specific behavior.

Generated from the current SKILL.md. These answers refresh after source changes.