Catalog
github/react18-lifecycle-patterns

github

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.

v1.0Latest
New~896Updated Jun 26, 2026

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.

Files4
4 files · 14.4 KB

Select a file to preview

Overall Score

88/100

Grade

A

Excellent

Safety

92

Quality

86

Clarity

89

Completeness

83

Summary

A comprehensive reference guide for migrating unsafe React class component lifecycle methods (componentWillMount, componentWillReceiveProps, componentWillUpdate) to React 18.3.1-compliant patterns. The skill provides decision trees, before/after code examples, and trap documentation to guide developers through correct migration paths while avoiding common mistakes.

Detected Capabilities

code referencepattern matchingdecision guidancedocumentation

Trigger Keywords

Phrases that MCP clients use to match this skill to user intent.

migrate componentWillMountcomponentWillReceiveProps refactorgetDerivedStateFromProps decisionunsafe lifecycle warningsreact 18 lifecyclegetSnapshotBeforeUpdateconcurrent mode safety

Use Cases

  • Migrate componentWillMount to constructor or componentDidMount
  • Migrate componentWillReceiveProps to componentDidUpdate or getDerivedStateFromProps
  • Migrate componentWillUpdate to getSnapshotBeforeUpdate or componentDidUpdate
  • Fix React 18 UNSAFE_ lifecycle warnings with permanent solutions
  • Choose between getDerivedStateFromProps and componentDidUpdate for prop-change handling
  • Prevent multiple renders of side effects in concurrent mode

Quality Notes

  • Clear semantic categorization in decision tables routes developers to correct migrations
  • Comprehensive before/after code examples for all 6 major cases (3 methods × 2 patterns)
  • Well-documented traps in getDerivedStateFromProps section prevent subtle bugs (static method limitations, trap of firing on every render)
  • Reference files are well-organized with anchored sections enabling precise navigation
  • Explicit guidance on never using UNSAFE_ prefix as permanent fix, with TODO pattern for temporary usage
  • Covers edge cases like multiple patterns in one method and concurrent mode safety issues
  • Cancellation pattern for async operations shows production-grade request tracking
  • Could benefit from a quick visual comparison table showing all three lifecycle methods side-by-side
Model: claude-haiku-4-5-20251001Analyzed: Jun 26, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Use github/react18-lifecycle-patterns in your dev environment

Command Palette

Search for a command to run...