리액트 사용시 push 사용 하면 안된다.const array = [ ];
array.push(1)=>1array;=>[1] const array2 = [ ... array, 2]
기존 배열 복사해놓고, 새로운 것 넣어주기
shouldComponentUpdate(nextProps, nextState, nextContext){
if(this.state.counter !== nextState.counter){
return true; // 현재 state coutner와 다음 state coutner 값이 다르면 렌더링.
}
return false;
}
************************************************************************
{PureComponent}를 대신 사용해도 렌더링 성능이 좋아진다.
=>shouldComponentUpdate(nextProps, nextState, nextContext)를 자동으로 해준다.
ex)
import React, {PureComponent} from 'react';
class test extends PureComponent {
}
* 바뀌는 경우만 자동으로 확인해주고 렌더링 해준다.
* 옛날 객체 그대로 가지고 오면 안된다.
* 새로운 객체, 배열을 펼쳐서 추가를 해줘야 한다.
'TIL > REACT' 카테고리의 다른 글
props 는 부모가 설정. (props 추가설명) (0) | 2019.10.11 |
---|---|
this.setState => render() 실행! (0) | 2019.10.11 |
PureComponent & props 사용 방법 (0) | 2019.10.11 |
리액트 Component & props (0) | 2019.10.11 |
React requirements - node js, npm , git (0) | 2019.10.11 |
comment