子组件:
import React from 'react';
let Course = (props) => {
return (<div>
<input type="button" value="fff" />
<p onClick={props.click}>我是{props.title}课程哦{props.count}</p>
<p>{props.children}</p>
</div>);
}
export default Course;
父组件:
import React, { Component } from 'react';
class Student extends Component {
state = {
showTime: false
}
xinashitime = () => {
this.setState({
showTime: !this.state.showTime
}
)
}
render() {
console.log("触发了stdent")
let myzujian = null;
console.log("显示状态:" + this.state.showTime)
if (this.state.showTime) {
myzujian = (
<div>
<h2>你出来就舒服了</h2>
</div>
)
}
return (
<div>
我的标题是:{this.props.title}
<button onClick={this.xinashitime}>显示时间</button>
<div>
<Teacher name={"科比"} />
{myzujian}
</div>
</div>
)
}
}
let Teacher = (props) => {
return (
<div>老师好:{props.name}</div>
)
}
export default Student;
export { Teacher };
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();