1 目录结构
2 index.js
/*
应用的入口组件:作用是渲染组件
* */
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
//将App组件标签渲染到index页面的div上
ReactDOM .render(<App/>,document.getElementById('root'));
3 App.js
/*
应用的根组件
* */
import React,{Component} from 'react'
export default class App extends Component{
//必须有render且必须返回一个DOM虚拟对象
render(){
return <div>App</div>
}
}
4 public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>