개인공부/React

React 공부 - 6일차

왕큰새 2021. 3. 1. 18:48
728x90

React LifeCycle 순서 

 

class -> constructor -> render -> ref -> componentDidMount

 

(setState/props 바뀔 때) -> shouldComponentUpdate(true) -> render -> componentDidUpdate()

 

부모가 자식 컴포넌트 없앴을 때 -> componentWillUnmount() -> 소멸

 

 

 

react가 dom 에 표시할 때 특정한 동작을 할 수 있음  

 

render 가 처음 성공적으로 실행 됬다면 componentDidMount 실행 됨.

setState같은 것으로로 리렌더링 일어날 때는 componentDidMonut 실행 안됨 

 

 

componentDidMount() { }

컴포넌트 첫 렌더링 된 후 -> 비동기 요청을 많이 함 setInterval() 등

비동기 함수 밖에 있는 변수 참조하면 클로저 문제 발생 ( Javascript ) 

componentDidUpdate { } 

리렌더링후 작동

  componentWillUnmount() {  }

 

컴포넌트 제거되기 직전 , 비동기 요청 정리 clearInterval()