问题描述:
当在浏览器中刷新页面时,如下示例代码:
class Test extends Component {
constructor(props) {
super(props)
this.state = {}
}
componentWillMount() {
// 获取所有活动数据
...code
}
render() {
const { Test } = this.props;
console.log(Test)
return (
<div>
<span>这是一段测试代码</span>
</div>
)
}
会发现在浏览器后台打印出多次Test,其中前几次多为空对象,那么应该如何避免这种情况呢?
shouldComponentUpdate
是可以控制是否渲染更新的