We recommend using a bundler like webpack or Browserify so you can write modular code and bundle it together into small packages to optimize load time.
我们建议使用像webpack或Browserify这样的打包器,以便您可以编写模块化代码,并将它们捆绑到小型软件包中以优化加载时间。
The smallest React example looks like this:
最小的React示例如下所示:
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>hello, world!</h1>
document.getElementById('root')
);
This code renders into a DOM element with the id of root so you need <div id="root"></div> somewhere in your HTML file.
这段代码被渲染到id为root的DOM元素中,是你的HTML文件需要一个 <div id="root"></div>
Similarly, you can render a React component inside a DOM element somewhere inside your existing app written with any other JavaScript UI library.
同样,你可以把一个React组件渲染到使用其他JavaScript UI库的现有应用的DOM内部中。