New to Claude Skills? Learn how to install them →

Rgithub on GitHub

React 18 Lifecycle Patterns

OfficialFree

Migrate unsafe React lifecycle methods with precision.

by github37.7k stars on github/awesome-copilot
1 views
Updated Aug 10, 2026
Get this skill

Free · Opens the source repo

What React 18 Lifecycle Patterns does

The React 18 Lifecycle Patterns skill provides developers with a structured approach to migrating unsafe class component lifecycle methods to compliant patterns in React 18.3.1. This skill focuses on three specific methods: componentWillMount, componentWillReceiveProps, and componentWillUpdate, which are deprecated in favor of safer alternatives. By using this skill, developers can avoid common pitfalls and ensure that their migration process is both accurate and efficient.

When migrating a lifecycle method, it is crucial to understand its semantic purpose. The skill includes a quick decision guide that categorizes the actions of each lifecycle method, directing developers to the appropriate migration pattern. For example, if componentWillMount is used to set initial state, the skill advises moving this logic to the constructor. Conversely, if it runs side effects, it should be migrated to componentDidMount. This level of granularity helps prevent migration errors that could lead to bugs in the application.

Additionally, the skill emphasizes the importance of avoiding the use of the UNSAFE_ prefix as a long-term solution. While prefixing can suppress warnings, it does not address the underlying issues associated with concurrent mode safety or prepare the code for future React versions. The skill provides clear guidelines on marking temporary additions and scheduling proper migration efforts, ensuring that developers are aware of the implications of their choices.

Overall, this skill is an essential resource for React developers looking to modernize their codebases while adhering to best practices. By following the provided decision trees and reference files, users can confidently navigate the complexities of lifecycle method migration in React 18.

When to use it

Use this skill when you need to migrate class component lifecycle methods to comply with React 18 standards.

When not to use it

This skill is not suitable for projects that do not use class components or for those already using functional components with hooks.

What you can build with it

Migrating a Legacy Component

You have an existing class component that uses `componentWillMount` and need to migrate it to comply with React 18.

Resolving UNSAFE_ Warnings

Your application is showing warnings for unsafe lifecycle methods, and you want to address them before upgrading React.

Implementing New Lifecycle Patterns

You're adding new features to a class component and need to ensure the lifecycle methods are correctly implemented according to React 18 standards.

How to install React 18 Lifecycle Patterns

View source

1. Install with the skills CLI

npx skills add github/awesome-copilot/react18-lifecycle-patterns --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by 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 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.

Frequently asked questions about React 18 Lifecycle Patterns

Similar skills