Skip to main content
skill GitHub Copilot official · GitHub

react18-lifecycle-patterns — GitHub Copilot skill: what it does

Migrates unsafe class component lifecycle methods to React 18.3.1 patterns. Helps prepare legacy code for React 19 before breaking changes arrive.

Install into GitHub Copilot · Skills CLI (Vercel) All methods and platforms ↓
npx skills add github/awesome-copilot --skill react18-lifecycle-patterns
Open on GitHub

What react18-lifecycle-patterns does

The skill provides decision trees and migration patterns for three methods: componentWillMount, componentWillReceiveProps, and componentWillUpdate. It helps determine the semantic category of code before rewriting it. Logic moves into constructor, componentDidMount, componentDidUpdate, getDerivedStateFromProps, or getSnapshotBeforeUpdate.

Three reference files supply before-and-after code examples for specific cases. These cover DOM reading before updates, async requests, and prop-to-state derivations. It also warns against common traps in getDerivedStateFromProps.

Adding the UNSAFE_ prefix only silences React 18.3.1 warnings. React 19 removes these lifecycle methods entirely. This skill is necessary when maintaining legacy class components that must survive future upgrades.

What it helps with

  • migrate legacy componentWillMount code to componentDidMount or constructor
  • replace componentWillReceiveProps with componentDidUpdate or getDerivedStateFromProps
  • handle DOM measurements via getSnapshotBeforeUpdate instead of componentWillUpdate
  • resolve React 18.3.1 lifecycle warnings before upgrading to React 19

Example prompts for the agent

  • Migrate componentWillReceiveProps in this class component to React 18.3.1 patterns
  • Where should I move state derivation from componentWillMount?
  • Help me replace componentWillUpdate with getSnapshotBeforeUpdate

How to install react18-lifecycle-patterns

1Skills CLI (Vercel)

npx skills add github/awesome-copilot --skill react18-lifecycle-patterns

2GitHub CLI

gh skill install github/awesome-copilot react18-lifecycle-patterns

3Manually: put the files in place

.github/skills/react18-lifecycle-patterns/SKILL.md

From the same set554

The whole set →
git-commit official github This skill reviews Git changes, stages related files, and creates Conventional Commits. Use it when you want an agent to make one commit or split work into separate commits. GitHub Copilot 47,165installs excalidraw-diagram-generator official github Turn a plain-language description into an Excalidraw diagram. Useful for mapping processes, system structure, and relationships between entities. GitHub Copilot 31,639installs multi-stage-dockerfile official github This skill guides GitHub Copilot in writing multi-stage Dockerfiles for different languages and frameworks. Use it when the final runtime image should contain fewer build dependencies. GitHub Copilot 29,688installs documentation-writer official github Skill that turns the agent into a technical writer following the Diátaxis framework: tutorials, how-to guides, reference, and explanation. Proposes structure before writing. GitHub Copilot 27,757installs prd official github Turns a feature idea into a structured PRD with user stories, technical requirements, and risks. Use it when planning a software feature or an AI-powered one. GitHub Copilot 24,035installs refactor official github This skill reshapes existing code without changing its external behavior. Use it for gradual cleanup of large functions, duplication, weak types, and code smells. GitHub Copilot 22,321installs java-springboot official github Gives GitHub Copilot Spring Boot development practices, from project layout to tests and security. Use it when writing or reviewing Java application code. GitHub Copilot 21,272installs create-readme official github This skill reviews a project and creates a structured README.md. Use it when the repository needs clear documentation based on its actual files and code. GitHub Copilot 19,081installs

Similar

Questions about react18-lifecycle-patterns

How to install react18-lifecycle-patterns in GitHub Copilot?

Run npx skills add github/awesome-copilot --skill react18-lifecycle-patterns in your terminal or install via gh skill install github/awesome-copilot react18-lifecycle-patterns.

What does react18-lifecycle-patterns do?

It guides developers through migrating unsafe React class lifecycles into supported React 18.3.1 patterns using reference examples.

Why not just rename methods with the UNSAFE_ prefix?

The UNSAFE_ prefix suppresses React 18.3.1 warnings without fixing concurrent mode safety. React 19 removes these methods completely, even with the prefix.

Source text

SKILL.md · MIT
---
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 does | Correct migration | Reference |
|---|---|---|
| Sets initial state (`this.setState(...)`) | Move to `constructor` | [→ componentWillMount.md](references/componentWillMount.md#case-a) |
| Runs a side effect (fetch, subscription, DOM) | Move to `componentDidMount` | [→ componentWillMount.md](references/componentWillMount.md#case-b) |
| Derives initial state from props | Move to `constructor` with props | [→ componentWillMount.md](references/componentWillMount.md#case-c) |

### componentWillReceiveProps - what does it do?

| What it does | Correct migration | Reference |
|---|---|---|
| Async side effect triggered by prop change (fetch, cancel) | `componentDidUpdate` | [→ componentWillReceiveProps.md](references/componentWillReceiveProps.md#case-a) |
| Pure state derivation from new props (no side effects) | `getDerivedStateFromProps` | [→ componentWillReceiveProps.md](references/componentWillReceiveProps.md#case-b) |

### componentWillUpdate - what does it do?

| What it does | Correct migration | Reference |
|---|---|---|
| Reads the DOM before update (scroll, size, position) | `getSnapshotBeforeUpdate` | [→ componentWillUpdate.md](references/componentWillUpdate.md#case-a) |
| Cancels requests / runs effects before update | `componentDidUpdate` with prev comparison | [→ componentWillUpdate.md](references/componentWillUpdate.md#case-b) |

---

## 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:
```jsx
// 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.

© github · MIT · github/awesome-copilot

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor