Today I Learned

[아티클 DB] React 16 Lifecycle Methods: How and When to Use Them

아이리스 Iris 2023. 2. 13. 20:15

https://medium.com/bitsrc/react-16-lifecycle-methods-how-and-when-to-use-them-f4ad31fb2282

 

React 16 Lifecycle Methods: How and When to Use Them

A revised and up-to-date guide to the new React component lifecycle

blog.bitsrc.io


리액트의 생명주기

컴포넌트는 생성(mounting) → 업데이트(updating) → 제거(unmounting)의 생명주기를 갖는다.
  • 클래스 컴포넌트 → Lifecycle methods
  • 함수형 컴포넌트 → Hook

클래스 컴포넌트의 생명주기

React lifecycle methods diagram
React lifecycle methods diagram

Mounting

  • constructor
  • getDerivedStateFromProps
  • render
  • componentDidMount

Updating

  • getDerivedStateFromProps
  • shouldComponentUpdate
  • render
  • getSnapshotBeforeUpdate (New!)
  • componentDidUpdate

Unmounting

  • componentWillUnmount

Errors

  • getDerivedStateFromError
  • componentDidCatch

클래스 컴포넌트가 어떤 순서로 어떤 함수를 사용하며 렌더링 되는지 전체적인 틀은 잡혔는데, 아무래도 직접 구현해 보기 전까지는 두루뭉술한 상태일 것 같다.

 

🤔 클래스 컴포넌트 생명주기 구현