鍍金池/ 問答/HTML5  HTML/ forceUpdate setState有什么區(qū)別

forceUpdate setState有什么區(qū)別

請問forceUpdate setState有什么區(qū)別呢?
什么時候用forceUpdate?
求解?

回答
編輯回答
哎呦喂

forceUpdate會跳過shouldComponentUpdate步驟直接觸發(fā)組件的render方法
官網(wǎng)建議應(yīng)該盡量避免使用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...
2018年2月10日 16:52
編輯回答
假灑脫

有些時候你的變量并不在 state 上,比如 this.couter 等,當這些變量改變是 React 組件是并不會重新執(zhí)行 render 的,因此需要組件強制調(diào)用 render 方法。

2018年9月9日 12:50