< em > < / em >反应包包含:React。createElement,反应。createClass,反应。组件,反应。proptype,反应。孩子们
< em > React-dom < / em >包包含:ReactDOM。渲染,ReactDOM。unmountComponentAtNode ReactDOM。findDOMNode和react-dom/server,包括:ReactDOMServer。renderToString和ReactDOMServer.renderToStaticMarkup。
import React from 'react';
import * as ReactDOM from 'react-dom/client';
ReactDOM
.createRoot(document.getElementById('root'))
.render(<h1>Hello, world!</h1>);
或者使用一个常量,如果你不喜欢链接,这只是一个风格的问题:
import React from 'react';
import * as ReactDOM from 'react-dom/client';
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(<h1>Hello, world!</h1>);