1. //Tips:每个页面级的组件第一行必须加
  2. import React from 'react'

1.无状态组件

  1. //就是一个函数,无状态组件中不能写事件,不能对
  2. import React from 'react';
  3. function App() {
  4. return (
  5. <div className="App" >
  6. hello world
  7. </div>
  8. );
  9. }
  10. export default App;

2.有状态组件

有状态组件要写在render中

  1. import React from 'react';
  2. class App extends React.Component{
  3. //数据放在构造函数的state属性中
  4. constructor(props){
  5. super(props);
  6. this.state={
  7. msg:"hello world"
  8. }
  9. }
  10. render(){
  11. return(
  12. //使用数据 {this.state.msg}
  13. <div>{this.state.msg}</div>
  14. )
  15. }
  16. }
  17. export default App;