react18-lifecycle-patterns — скилл для GitHub Copilot
Переводит устаревшие методы жизненного цикла классовых компонентов на стандарт React 18.3.1. Пригодится при подготовке легаси-кода к React 19.
npx skills add github/awesome-copilot --skill react18-lifecycle-patterns -a claude-codeЧто делает react18-lifecycle-patterns
Скилл содержит деревья решений и шаблоны миграции для трех методов: componentWillMount, componentWillReceiveProps и componentWillUpdate. Вместо механической вставки префикса UNSAFE_ он распределяет код по смысловым категориям. Логика переносится в constructor, componentDidMount, componentDidUpdate, getDerivedStateFromProps или getSnapshotBeforeUpdate.
Внутри лежат три справочных файла с примерами до и после под конкретные сценарии. Скилл разбирает чтение DOM перед обновлением и отмену сетевых запросов. Он также предостерегает от типичных ошибок с getDerivedStateFromProps.
Префикс UNSAFE_ лишь временно скрывает ворнинги React 18.3.1. В React 19 эти вызовы удалят окончательно. Скилл нужен тем, кто обновляет старую кодовую базу с классовыми компонентами.
Какие задачи решает
- убрать предупреждения об устаревших методах в React 18.3.1
- заменить componentWillReceiveProps на componentDidUpdate или getDerivedStateFromProps
- перенести сайд-эффекты из componentWillMount в componentDidMount
- подготовить классовые компоненты к переходу на React 19
Примеры запросов агенту
- Помоги переписать componentWillReceiveProps в этом классовом компоненте под React 18.3.1
- Куда перенести запрос данных из componentWillMount?
- Проверь компонент и замени UNSAFE_ методы на актуальные паттерны
Как установить react18-lifecycle-patterns
1Через Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill react18-lifecycle-patterns -a claude-code2Вручную: положить файлы
~/.claude/skills/react18-lifecycle-patterns/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/react18-lifecycle-patterns/
Вручную: положить файлы
.agents/skills/react18-lifecycle-patterns/SKILL.mdДля всех проектов — ~/.agents/skills/
Вручную: положить файлы
.cursor/skills/react18-lifecycle-patterns/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1Через Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill react18-lifecycle-patterns2GitHub CLI
gh skill install github/awesome-copilot react18-lifecycle-patterns3Вручную: положить файлы
.github/skills/react18-lifecycle-patterns/SKILL.mdКомандой платформы
gemini skills install https://github.com/github/awesome-copilot --path skills/react18-lifecycle-patternsВручную: положить файлы
.devin/skills/react18-lifecycle-patterns/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Claude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
Из того же набора554
Весь набор →Похожие
Вопросы о react18-lifecycle-patterns
Как установить react18-lifecycle-patterns в GitHub Copilot?
Выполните команду npx skills add github/awesome-copilot --skill react18-lifecycle-patterns в терминале или добавьте файл .github/skills/react18-lifecycle-patterns/SKILL.md.
Что делает скилл react18-lifecycle-patterns?
Он предоставляет готовые сценарии миграции методов componentWillMount, componentWillReceiveProps и componentWillUpdate на безопасные паттерны React 18.3.1.
Почему нельзя просто добавить префикс UNSAFE_?
Префикс скрывает предупреждение в React 18.3.1, но не решает проблем с concurrent mode. В React 19 эти методы будут удалены даже с префиксом.
Исходный текст
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