사용하여 렌더링 조건을 설정.(hook는 useEffect등 이용)
class Test extends Component {
state = {
counter: 0,
};
shouldComponentUpdate(nextProps, nextState, nexContext) {
if (this.state.counter !== nextState.counter) {
return true;
}
return false;
}
onClick = () => {
this.setState({});
};
render() {
return (
<div>
<button onClick={this.onClick}>클릭</button>
</div>
);
}
}
import React, {PureComponet} from 'react';
class Test2 extends PureComponent {
state = {
counter: 0,
try: 'hello',
number: 1,
boolean: true,
object: {},
array: [],
};
onClick = () => {
this.setState({
array: [...this.state.array, 1],
});
};
render() {
return (
<div>
<button onClick={this.onClick}>클릭</button>
</div>
);
}
}