在事件处理程序中访问 this.state 有多安全?

How safe is to access this.state inside an event handler?

React Native 文档在 forceUpdate 的文档中讲述(这可能被认为有助于立即将对 setState 的最后一次调用同步到实际的 this.state 对象以使用它们值):

Normally you should try to avoid all uses of forceUpdate() and only read from this.props and this.state in render(). This makes your component "pure" and your application much simpler and more efficient.

这是否意味着在作为事件处理程序调用的函数(例如 onScrollonEndReached、.. .) 或者那些事件是否包含在渲染周期内?

我无法自信地回答您的问题,但请记住,您可以将回调传递给 setState,这意味着后续调用将作用于新状态。如果您必须使用 forceUpdate,您最有可能尝试做错事。

The second (optional) parameter is a callback function that will be executed once setState is completed and the component is re-rendered.