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這樣的打包器,以便您可以編寫(xiě)模塊化代碼,并將它們捆綁到小型軟件包中以?xún)?yōu)化加載時(shí)間。
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文件需要一個(gè) <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.
同樣,你可以把一個(gè)React組件渲染到使用其他JavaScript UI庫(kù)的現(xiàn)有應(yīng)用的DOM內(nèi)部中。