首页 > 解决方案 > 当我们在 react 中点击 componentDidMount 时,组件安装在哪里?它是真正的 DOM 还是 VirtualDom?

问题描述

你什么时候会在 react 中点击 componentDidMount 钩子?是在组件安装到虚拟 dom 还是实际 dom 时?

标签: reactjsreact-lifecycle-hooks

解决方案


render()该组件在“渲染阶段”安装到虚拟 DOM 。

生命componentDidMount周期是“提交阶段”的一部分,被挂载到实际的 DOM。

请注意,如果您调用setState.componentDidMount

您可以setState()立即致电componentDidMount()。它会触发额外的渲染,但会在浏览器更新屏幕之前发生。


推荐阅读