본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)40k · #7387

react18-lifecycle-patterns

하는 일

오래된 React 코드의 '생명주기' 메서드를 최신 버전에 맞게 옮기도록 돕습니다. 코드 조각을 최신 React 버전과 잘 작동하는 올바른 위치로 옮기는 방법을 보여 줍니다.

사용하는 경우

  • ✓더 이상 권장되지 않는 생명주기 메서드를 쓰는 오래된 React 코드가 있을 때.
  • ✓getDerivedStateFromProps와 componentDidUpdate 중 무엇을 쓸지 결정할 때.
  • ✓업데이트를 처리하기 위해 getSnapshotBeforeUpdate를 추가해야 할 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/react18-lifecycle-patterns/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/react18-lifecycle-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“React 컴포넌트에서 초기 상태를 설정하는 componentWillMount 메서드를 어떻게 옮기나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 가이드는 오래된 메서드가 하던 일을 React 18에서 같은 일을 하는 새 방법과 비교합니다. 오래된 메서드의 기능에 따라 구체적인 예시를 안내합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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 code
  • references/componentWillReceiveProps.md - getDerivedStateFromProps trap warnings, full examples
  • references/componentWillUpdate.md - getSnapshotBeforeUpdate + componentDidUpdate pairing

Read the relevant file before writing any migration code.

자주 묻는 질문

'생명주기 메서드'는 무엇인가요?

React 컴포넌트에서 생성, 업데이트, 제거 같은 특정 시점에 코드를 실행하는 특별한 함수입니다.

'UNSAFE_componentWillMount' 같은 오래된 메서드를 그냥 쓰면 안 되나요?

'UNSAFE_' 접두사는 경고만 숨길 뿐, 최신 React 버전과의 호환성 문제를 고치지 않습니다. 영구적인 해결책이 아니라 임시방편입니다.

옮기기 위한 코드 예시는 어디에 있나요?

자세한 예시는 'componentWillMount.md', 'componentWillReceiveProps.md', 'componentWillUpdate.md' 같은 별도 참고 파일에 있으며, 이 가이드가 그 파일을 가리킵니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
40k
순위
#7387
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬