[React] React Lifecycle

Steve·2021년 6월 14일
0

공부

목록 보기
9/10

Component 의 lifecycle 을 쉽게 설명
https://www.w3schools.com/react/react_lifecycle.asp

React 공식 문서 lifecycle 설명
https://reactjs.org/docs/react-component.html

React component 는

  1. Mounting
    - putting elements into the DOM
  2. Updating
    - A component is updated whenever there is a change in the component's state or props.)
  3. Unmounting
    - when a component is removed from the DOM

의 세 단계가 있는데 이 단계마다 메소드를 사용하여 컴포넌트를 조작할 수 있다. 이 메소드들을 lifecycle methods 라고 한다.

오직 class 컴포넌트에서만 lifecycle method 들을 쓸 수 있다. Hooks 의 등장으로 인해 리엑트 컴포넌트가 class 에서 function 으로 넘어오면서 lifecycle method 들은 function 컴포넌트에는 쓸 수 없다.

Hooks 는 function 컴포넌트에서만 쓸 수 있다. Hooks 로 인해 function component 가 자리잡게 되었고, 결론적으로 컴포넌트 사용이 더 쉬워졌다.

profile
게임과 프론트엔드에 관심이 많습니다.

0개의 댓글