请问forceUpdate setState有什么区别呢?
什么时候用forceUpdate?
求解?
forceUpdate会跳过shouldComponentUpdate步骤直接触发组件的render方法
官网建议应该尽量避免使用forceUpdate
Normally you should try to avoid all uses of forceUpdate() and only read from this.props and this.state in render().
https://reactjs.org/docs/reac...
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
有些时候你的变量并不在 state 上,比如
this.couter
等,当这些变量改变是 React 组件是并不会重新执行 render 的,因此需要组件强制调用 render 方法。