Home,js
import React, {Component} from 'react';
import News from "./News";
class Home extends Component {render() {return (<div>home<News name="你好"/></div>);}
}export default Home;
news,js
import React, {Component} from 'react';
import PropTypes from 'prop-types';class News extends Component {constructor(props) {super(props);this.state={num:1111}}fun(){this.setState({num:222})}render() {return (<div>News-----{this.props.name}-----{this.state.num}<button onClick={this.fun.bind(this)}>哈哈</button></div>);}
}News.propTypes = {};export default News;
app.js
import React from 'react';import './App.css';
import Home from './components/Home.js'
function App() {return (<div className="App">你好<Home></Home></div>);
}export default App;