Pau*_*aul 3 html javascript frontend webstorm reactjs
我想在静态HTML页面的div中添加一个React组件。我这样做不是将整个页面转换为React,因为我只需要在我的网页的某些部分使用React。我按照https://reactjs.org/docs/add-react-to-a-website.html上的说明进行操作。我的问题是:
看看这个最小的例子。您需要包含3个脚本
- react.development.js(react库)
- react-dom.development.js(与lib进行交互的dom)
- babel.min.js(将React JSX转换为与浏览器兼容的JS)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<!-- Don't use this in production: -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function HelloWorld(props){
return <h1>{`Hello, world! ${props.name}`}</h1>;
}
ReactDOM.render(
<HelloWorld name="James"/>,
document.getElementById('root')
);
</script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
Note: this is a great way to try React but it's not suitable for production. It slowly compiles JSX with Babel in the browser and uses a large development build of React.
Read this section for a production-ready setup with JSX:
https://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project
In a larger project, you can use an integrated toolchain that
includes JSX instead:
https://reactjs.org/docs/create-a-new-react-app.html
SOURCE : https://raw.githubusercontent.com/reactjs/reactjs.org/master/static/html/single-file-example.html