react18-lifecycle-patterns

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.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "react18-lifecycle-patterns" with this command: npx skills add github/awesome-copilot/github-awesome-copilot-react18-lifecycle-patterns

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 doesCorrect migrationReference
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 propsMove to constructor with props→ componentWillMount.md

componentWillReceiveProps - what does it do?

What it doesCorrect migrationReference
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 doesCorrect migrationReference
Reads the DOM before update (scroll, size, position)getSnapshotBeforeUpdate→ componentWillUpdate.md
Cancels requests / runs effects before updatecomponentDidUpdate 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 Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

git-commit

No summary provided by upstream source.

Repository SourceNeeds Review
23.6K-github
Coding

gh-cli

No summary provided by upstream source.

Repository SourceNeeds Review
17.5K-github
Coding

prd

No summary provided by upstream source.

Repository SourceNeeds Review
14.4K-github
Coding

documentation-writer

No summary provided by upstream source.

Repository SourceNeeds Review
14.3K-github
react18-lifecycle-patterns | V50.AI