PluginBench
Skill
Official
Pass
Audit score 90

react18-lifecycle-patterns

github/awesome-copilot

How to install react18-lifecycle-patterns

npx skills add https://github.com/github/awesome-copilot --skill react18-lifecycle-patterns
Claude Code
Cursor
Windsurf
Cline
Full instructions (SKILL.md)

Source of truth, from github/awesome-copilot.


name: react18-lifecycle-patterns description: '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.'

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.

Related skills

More from github/awesome-copilot and the wider catalog.

REreact18-string-refs logo

react18-string-refs

Official
github/awesome-copilot

Provides exact migration patterns for React string refs (ref="name" + this.refs.name) to React.createRef() in class components. Use this skill whenever migrating string ref usage - including single element refs, multiple refs in a component, refs in lists, callback refs, and refs passed to child components. Always use this skill before writing any ref migration code - the multiple-refs-in-list pattern is particularly tricky and this skill prevents the most common mistakes. Use it for React 18.3.1 migration (string refs warn) and React 19 migration (string refs removed).

690 installsAudited
REreact19-concurrent-patterns logo

react19-concurrent-patterns

Official
github/awesome-copilot

Preserve React 18 concurrent patterns and adopt React 19 APIs (useTransition, useDeferredValue, Suspense, use(), useOptimistic, Actions) during migration.

807 installsAudited
REreact19-source-patterns logo

react19-source-patterns

Official
github/awesome-copilot

Reference for React 19 source-file migration patterns, including API changes, ref handling, and context updates.

777 installsAudited
REreact19-test-patterns logo

react19-test-patterns

Official
github/awesome-copilot

Provides before/after patterns for migrating test files to React 19 compatibility, including act() imports, Simulate removal, and StrictMode call count changes.

862 installsAudited
REreadme-blueprint-generator logo

readme-blueprint-generator

Official
github/awesome-copilot

Generate comprehensive README.md by analyzing project documentation structure and Copilot instructions.

9.2k installs
RErefactor logo

refactor

Official
github/awesome-copilot

Surgical code refactoring to improve maintainability without changing behavior.

19k installsAudited