通常,您必须在模板中放置一个根元素,例如<div id="root"></div>. 然后使用 React/jsx,将组件(及其子组件)渲染到root. 该组件(渲染时)可能如下所示<div id="main-wrapper">。最终渲染将有两个根,一个称为 root,一个称为 main-wrapper。有没有更干净的方法来使用 React 进行渲染?
而不是这个:
<div id="root">
<div id="main-wrapper>
<section></section>
<section></section>
. . .
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我可以这样做吗?
<div id="root">
<section></section>
<section></section>
. . .
</div>
Run Code Online (Sandbox Code Playgroud)