React 编写最简单的组件

创建一个文件,名为:HelloMessage.js。

import React, { Component } from 'react';

class HelloMessage extends Component {
    render() {
        return <div>Hello {this.props.name}</div>;
    }
}

export default HelloMessage;

App.js 调用:

import React, { Component } from 'react';
import HelloMessage from './HelloMessage';

class App extends Component {
  render() {
    return (
      <HelloMessage name={"米子才"} />
    );
  }
}

export default App;