본문 바로가기

공부/React

shouldComponentUpdate

shouldComponentUpdate

  • 컴포넌트의 render 함수가 실행돼야 하는지, 실행되지 않아야 하는지를 결정할 수 있게 해주는 함수
    • render 는 비용이 많이든다.
  • props, state 의 변경에 따라 호출된다.
  • render 이전에 shouldComponentUpdate 실행된다.
  • shouldComponentUpdate 의 반환값이 true 이면 render가 호출되고, false 이면 render가 호출되지 않는다.
  • shouldComponentUpdate 를 통해 새롭게 바뀐 값과 이전 값에 접근할 수 있다.
    • newProps 로 새롭게 바뀐 값 접근
    • this.props 를 통해 현재 값 접근

 

shouldComponentUpdatE(newProps, newState) { return false; }

'공부 > React' 카테고리의 다른 글

class vs function  (0) 2022.06.19
props & state  (0) 2022.06.19
State and Lifecycle  (0) 2022.03.01
Components와 Props  (0) 2022.02.28