Automated summary
Provides exact before/after migration patterns for replacing the three unsafe class component lifecycle methods (componentWillMount, componentWillReceiveProps, componentWillUpdate) with React 18.3.1 compliant equivalents.
Strengths
- Per-method decision trees route to the right replacement based on the semantic category of the behavior
- Reference files include full before/after code for every case
- Explicitly warns that the UNSAFE_ prefix is not a permanent fix
- Covers pairing getSnapshotBeforeUpdate with componentDidUpdate
Limitations
- Focused on class components and React 18.3.1 only, not on converting to hooks
- Does not cover other lifecycle methods or concurrent-mode APIs
- Assumes the developer has already identified which method needs migrating
Use whenever a React class component needs its unsafe lifecycle methods migrated, or when deciding between getDerivedStateFromProps and componentDidUpdate.
Avoid when the goal is modernizing code to function components with hooks, since this guide stays class-based.
Security analysis
SafePure documentation and migration guidance for React class lifecycle methods; no executable commands, network access, secrets handling, or destructive instructions.
No concerns found
How this analysis is madeExamples
This class component calls this.setState in componentWillMount to initialize a default value. Show me the correct React 18.3.1 migration and rewrite the code.My componentWillReceiveProps fetches data whenever a userId prop changes. Should I use getDerivedStateFromProps or componentDidUpdate? Give me the migrated code.I have a componentWillUpdate that reads scroll position before the DOM updates. Migrate it to getSnapshotBeforeUpdate paired with componentDidUpdate in React 18.3.1.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 |
| 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 codereferences/componentWillReceiveProps.md- getDerivedStateFromProps trap warnings, full examplesreferences/componentWillUpdate.md- getSnapshotBeforeUpdate + componentDidUpdate pairing
Read the relevant file before writing any migration code.
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/react-18-lifecycle-patterns-mrwakfj6/download' --output '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md.part' && mv '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md.part' '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md' && test -s '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/react18-lifecycle-patterns' && cp -R '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6' '.claude/skills/react18-lifecycle-patterns'Cursor
test -f '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md' && test -s '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/react18-lifecycle-patterns' && cp -R '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6' '.cursor/skills/react18-lifecycle-patterns'Codex
test -f '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md' && test -s '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/react18-lifecycle-patterns' && cp -R '.skill-downloads/react-18-lifecycle-patterns-mrwakfj6' '.agents/skills/react18-lifecycle-patterns'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/react-18-lifecycle-patterns-mrwakfj6'openskills read 'react-18-lifecycle-patterns-mrwakfj6'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/react-18-lifecycle-patterns-mrwakfj6/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
React Hook Form Best Practices
Development
Master React Hook Form: avoid anti-patterns, manage subscriptions, and handle reset, dirty state, and controlled inputs correctly.
Emotion to Mantine Migration
Development
Migrate Emotion styled-components to Mantine components with style props and CSS modules. Use when converting .styled.tsx files or removing @emotion imports.
Scope Creep Detector
Development
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad PRs, and oversized changes, then suggests keep, split, or justify actions.