/react18-upgrade:react18-lifecycle-patternsfrom react18-upgrade
Migrates unsafe React class component lifecycle methods (componentWillMount, componentWillReceiveProps, componentWillUpdate) to React 18.3.1-safe patterns with a decision guide for choosing the correct replacement.
Ships in react18-upgrade. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Classify the semantics of unsafe class lifecycle methods before changing code, then apply the matching React 18.3.1 migration pattern from the bundled references.
componentWillMount in this component."getDerivedStateFromProps or componentDidUpdate?"getSnapshotBeforeUpdate for scroll position."componentWillReceiveProps safely."componentWillMount, componentWillReceiveProps, or componentWillUpdate.UNSAFE_ prefixes; if a temporary prefix is unavoidable, add the required TODO.| What it does | Correct migration | Reference |
|---|---|---|
Sets initial state with this.setState(...) | Move to constructor. | references/componentWillMount.md#case-a |
| Runs a side effect such as fetch, subscription, or DOM access | Move to componentDidMount. | references/componentWillMount.md#case-b |
| Derives initial state from props | Move to constructor with props. | references/componentWillMount.md#case-c |
| What it does | Correct migration | Reference |
|---|---|---|
| Async side effect triggered by prop change, such as fetch or cancel | Use componentDidUpdate with previous-prop comparison. | references/componentWillReceiveProps.md#case-a |
| Pure state derivation from new props with no side effects | Use getDerivedStateFromProps. | references/componentWillReceiveProps.md#case-b |
| What it does | Correct migration | Reference |
|---|---|---|
| Reads DOM state before update, such as scroll, size, or position | Use getSnapshotBeforeUpdate and consume the snapshot in componentDidUpdate. | references/componentWillUpdate.md#case-a |
| Cancels requests or runs effects before update | Use componentDidUpdate with previous-value comparison. | references/componentWillUpdate.md#case-b |
Never use UNSAFE_componentWillMount, UNSAFE_componentWillReceiveProps, or UNSAFE_componentWillUpdate as a permanent fix. Prefixing suppresses React 18.3.1 warnings but does not fix concurrent mode safety issues, does not prepare for React 19 removal, and does not address the semantic migration.
If a temporary prefix is explicitly chosen as a stopgap, mark it with this exact intent:
// TODO: React 19 will remove this. Migrate before React 19 upgrade.
// UNSAFE_ prefix added temporarily - replace with componentDidMount / getDerivedStateFromProps / etc.
references/componentWillMount.md: three cases for initial state, side effects, and props-derived initial state.references/componentWillReceiveProps.md: componentDidUpdate versus getDerivedStateFromProps, including trap warnings.references/componentWillUpdate.md: getSnapshotBeforeUpdate plus componentDidUpdate pairing.componentWillReceiveProps belongs in componentDidUpdate, not getDerivedStateFromProps.getSnapshotBeforeUpdate is paired: DOM snapshots are returned before commit and consumed in componentDidUpdate.UNSAFE_ is not a migration: treat it only as a temporary scheduling marker.## React lifecycle migration
**Status:** complete | needs changes | blocked
**Component:** `<component name or path>`
**Original lifecycle:** `componentWillMount` | `componentWillReceiveProps` | `componentWillUpdate`
**Migration pattern:** `constructor` | `componentDidMount` | `componentDidUpdate` | `getDerivedStateFromProps` | `getSnapshotBeforeUpdate`
| Behavior found | Pattern applied | Reference | Validation |
| --- | --- | --- | --- |
| <state, side effect, DOM read, or cancel> | <new lifecycle/API> | `references/<file>.md#case-x` | <test/check> |
componentWillMount, componentWillReceiveProps, and componentWillUpdate are removed or explicitly justified as temporary UNSAFE_ stopgaps.getDerivedStateFromProps is used only for pure state derivation from props.getSnapshotBeforeUpdate with componentDidUpdate.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin react18-upgrade7 skills in this plugin
/react18-batching-patternsDiagnose and fix React 18 automatic batching regressions in class components. Use when multiple setState calls occur after await, inside setTimeout, Promise .then() or .catch(), native addEventListener callbacks, or when tests fail because they assert intermediate state after a React 18 upgrade./react18-dep-compatibilityCheck React 18.3.1 and React 19 dependency compatibility before npm installs, peer-dependency resolutions, or upgrade plans. Use when reviewing a React upgrade matrix, resolving npm peer conflicts, choosing minimum compatible package versions, deciding on --legacy-peer-deps, or separating a react-router v5 to v6 migration./Other plugins' skills for the same job