我一直在读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/