javascript - React 如何去除异步行为?

标签 javascript reactjs asynchronous

我一直在读this ,我在 Redux 文档中遇到了一行

Libraries like React attempt to solve this problem in the view layer by removing both asynchrony and direct DOM manipulation.

我理解 React 不允许 DOM 操作的部分,因为它使用 render() 方法抽象了实际渲染。我对第二部分感到困惑。

React 是如何去除异步的?有人可以用示例或有效用例进行解释吗。

最佳答案

它从设计上移除了 View 层的异步行为。您不得在 render 中执行异步操作,否则渲染的内容将被破坏。

Libraries like React attempt to solve this problem in the view layer by removing both asynchrony and direct DOM manipulation [from the render method].

你漏掉了最后一句,它给出了进一步的解释:

However, managing the state of your data is left up to you. This is where Redux enters.

总而言之,render 方法中必须没有异步调用,但 Redux 处理的状态管理部分可能会发生一些异步的事情。您不能按设计在渲染方法中执行异步操作。如果您这样做,它将不起作用。

关于javascript - React 如何去除异步行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40888733/

相关文章:

java - 并发远程数据处理

javascript - jQuery,循环遍历只有部分名称或 ID 已知的元素

css - 部分css添加flex后渲染延迟

reactjs - 如何使用antd React组件库在模态对话框中提交表单组件

javascript - React Native 中立即调用的 Click Handler

java - 使用java实时获取流程输出

javascript - 正确捕获异步函数node.js

javascript - 如何使用 jquery 显示子菜单?

javascript - JavaScript 中的 Facebook 服务器时间

javascript - 谷歌地图未捕获类型错误 : Cannot read property 'LatLng' of undefined