React触发页面渲染的几种方式

初始化

初次加载组件的时候,会调用一次render函数

更新

  1. state发生改变
  2. props发生改变

强制更新

如果不是前两种,还希望组件发生更新,可以使用
this.forceUpdate()

注意: <button onClick={() => this.forceUpdate()}>强制渲染 不可以写为<button onClick={this.forceUpdate}>强制渲染</button>

猜你喜欢

转载自www.cnblogs.com/sunhang32/p/12724134.html