react18-lifecycle-patterns
Fungsinya
Membantu memperbarui metode 'lifecycle' lama di kode React ke versi yang lebih baru. Panduan ini menunjukkan cara memindahkan bagian kode ke tempat yang tepat agar bekerja dengan baik di versi React terbaru.
Kapan dipakai
- ✓Saat Anda memiliki kode React lama yang memakai metode lifecycle yang sudah tidak direkomendasikan.
- ✓Saat memutuskan apakah akan menggunakan 'getDerivedStateFromProps' atau 'componentDidUpdate'.
- ✓Saat Anda perlu menambahkan 'getSnapshotBeforeUpdate' untuk menangani pembaruan.
Link skill
https://github.com/github/awesome-copilot/blob/main/skills/react18-lifecycle-patterns/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Bagaimana cara memigrasikan metode 'componentWillMount' yang mengatur state awal pada komponen React saya?”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Panduan ini membandingkan apa yang dilakukan metode lama dengan cara baru untuk melakukan hal yang sama di React 18. Panduan ini mengarahkan Anda ke contoh spesifik sesuai fungsi metode lama tersebut.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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 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.
Pertanyaan umum
Apa itu 'lifecycle methods'?
Ini adalah fungsi khusus dalam komponen React yang dijalankan pada waktu tertentu, misalnya saat komponen dibuat, diperbarui, atau dihapus.
Mengapa saya tidak bisa langsung memakai metode lama seperti 'UNSAFE_componentWillMount'?
Menggunakan awalan 'UNSAFE_' hanya menyembunyikan peringatan, tetapi tidak memperbaiki masalah kompatibilitas dengan versi React yang lebih baru. Ini hanya solusi sementara, bukan solusi permanen.
Di mana saya bisa menemukan contoh kode untuk migrasi?
Contoh lengkapnya ada di file referensi terpisah seperti 'componentWillMount.md', 'componentWillReceiveProps.md', dan 'componentWillUpdate.md', yang ditunjuk oleh panduan ini.
Detail
Deskripsi asli dari pembuat
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 fixi
repo: github/awesome-copilot
Popularitas
- Bintang GitHub
- 40k
- Peringkat
- #7387
- Lisensi
- MIT
- Diperbarui
- 15/10/2026
Komentar
- …
Skill lain dari repositori ini
acquire-codebase-knowledge
40kMembantu agent Anda memahami dan mendokumentasikan proyek kode yang sudah ada. Berguna untuk proses onboarding anggota baru atau mendapatkan gambaran arsitektur.
acreadiness-assess
40kMemungkinkan agent Anda menilai kesiapan proyek untuk AI dan membuat laporannya. Berguna untuk mengetahui seberapa siap proyek menggunakan alat AI.
acreadiness-generate-instructions
40kMembantu agent Anda membuat instruksi untuk alat AI berdasarkan hasil penilaian. Berguna untuk meningkatkan cara AI berinteraksi dengan kode dan menutup celah yang ditemukan.
acreadiness-policy
40kMemungkinkan agent Anda membantu menyusun atau menerapkan kebijakan untuk penilaian proyek AI. Berguna untuk menstandarisasi evaluasi proyek dan memastikan kepatuhan.
Skill serupa
angular-developer
280kMembantu agent Anda membuat kode Angular dan memberi saran struktur proyek. Berguna saat memulai proyek baru, membuat komponen, atau meningkatkan performa.
frontend-a11y
280kMembantu agent Anda membuat antarmuka web dapat diakses semua orang. Memastikan website dan aplikasi berfungsi baik dengan screen reader dan navigasi keyboard.
frontend-patterns
280kMembuat agent Anda menerapkan pola modern dalam frontend. Mengoptimalkan performa, mengelola state, dan mengikuti praktik terbaik React dan Next.js.