프론트 134 - class lifecycle

규링규링규리링·2024년 10월 1일

프론트 공부하기

목록 보기
134/135

class lifecycle

생명 주기

컴포넌트가 만들어졌을때 ~~해줘
컴포넌트가 죽으면 ~~ 해줘 이런것

컴포넌트 생명주기

  1. 그리기 / render
  2. 그리고 난 뒤 / componentDidMount
  3. 그리고 난 뒤 변경 되었을 때 / componentDidUpdate
  4. 그리고 난 뒤 사라질 때 / componentWillUnmount

언제 사용하나?

인풋창 그리고 난 뒤에 깜빡깜빡 해줘

예시

componentDidMount() : void{
  console.log("그려지고 나서 실행!!")
}
componentDidUpdate() : void{
  console.log("변경되고 나서 실행!!")
}
componentWillUnmount() : void{
  console.log("사라지기 전에 실행!!")
}

처음 페이지를 열면 componentDidMount 실행
카운트 올리기를 실행하면

componentDidUpdate 실행
마지막으로 나가기를 눌러서 다른 경로로 이동하려하면

이동되고 componentWillUnmount 기능이 실행됨

0개의 댓글