forceUpdate() 怎么理解?


原文地址: http://reactjs.cn/react/docs/working-with-the-browser.html

挂载的方法(Mounted Methods)中,有一段这么说的:
forceUpdate()当你知道一些很深的组件state已经改变了的时候,可以在该组件上面调用,而不是使用this.setState()。

这句话,还是无法让我理解forceUpdate(),到底是干嘛用的?有没有实例可以提供?为什么不是用setState?

reactjs JavaScript 技术文档

wdsfasd 8 years, 8 months ago

forceUpdate就是重新render。有些变量不在state上,但是你又想达到这个变量更新的时候,刷新render;或者state里的某个变量层次太深,更新的时候没有自动触发render。这些时候都可以手动调用forceUpdate自动触发render。所以建议使用immutable来操作state,redux等flux架构来管理state。

爱克丽丝汀 answered 8 years, 8 months ago

Your Answer