-
[항해 99 WIL] Life cycle && React Hooks개발일지/항해 99 2023. 7. 10. 00:22
Life cycle
생명주기라고도 불리는 이것은 컴포넌트가 생성되는 순간부터 사라지는 순간까지의 과정에서 어떠한 메서드가 실행이 되는지를 알 수 있는 것으로 클래스형컴포넌트를 많이 사용하는 그떄에는 필수적으로 알고있어야하지만 현재는 함수형컴포넌트가 대중화가 되고 클래스형 컴포넌트의 사용이 줄어들어 자세하게는 알 필요가 없다고 생각이 든다.
하지만 그중에서도 3가지는 알아야하는데 그게 마운트, 업데이트, 언마운트이다.
마운트
컴포넌트가 생성이 되었을 때를 나타내는 것으로 페이지가 랜더링되는것과 함수가 생성 및 실행되는 것이 모두 여기 담겨있다고 보면 된다
업데이트
state의 변화 props의 변화로 그리고 강제 업데이트로 인해서 리랜더링이 되었을때를 나타내는 것이라고 보면 된다
언마운트
함수가 사라졌을 때를 뜻하며 예를 들어 Router를 통해서 Home => Content 로 page의 이동이 있을 때에 Home은 언마운트 되고 Content는 마운트가 되는 것이다.
React Hooks
클래스형 컴포넌트에서 라이프사이클에 따른 메서드를 활용할 수 있었다면 함수형 컴포넌트에서는 그 역할을 React Hook이 해준다. 다양한 기능이 있으며 컴포넌트의 최적화를 위해서 또는 상태관리를 위해서 비동기 기통신 및 여러 기능 별로 존재하는 Hook이 많고 자주 사용하는 기능을 가지고 Custom Hook을 만들 수도 있어 매우 유용하다.
'개발일지 > 항해 99' 카테고리의 다른 글
[level4 1일차] 뭔가 엄청 이상한데 (0) 2023.07.10 [항해 99 주특기] Throttiling && Debouncing && Lodash (0) 2023.07.10 [WIL] 07. 10 ~ 07. 16 (0) 2023.07.10 [항해99 회고록] 3주차 주특기 Level-3 과제 (0) 2023.07.08 [항해 99 주특기] 심화강의 Thunk (0) 2023.07.04