在React中渲染组件
我有两个组件。组件 a 和组件 b 。我想在组件 a 完全渲染后渲染组件 b 。我使用useeffect
和uselayouteffect
挂钩,但是这些对我没有帮助。您的解决方案是什么?
I have two components. component A and component B. I want to render component B after component A is fully rendered. I used useEffect
and uselayoutEffect
hooks, but those didn't help me. What's your solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
渲染组件 a uselayouteffect 和组件 b
i特别喜欢 反应lazy lazy loading 组件
Render component A with uselayoutEffect and component B with
I specifically prefer React Lazy Loading components
下面的示例是使用
使用>使用
进行工作。一旦呈现&lt; app /&gt; < /code>,这意味着
&lt; componenta /&gt; < /code>是因为它是其子女之一,因此我们可以使用
使用
使用
更新状态并渲染
&lt; componentb/&gt;
:但是,如果您想使用很多组件进行此操作,这可能不是很有效。
The following example is working using
useEffect
. Once<App />
is rendered, that means<ComponentA />
is rendered because it is one of its children, so we can useuseEffect
to update the state and render<ComponentB />
:However, it may not be very efficient if you want to do this with a lot of components.