父组件向子组件传参
import Son from 'son'
class Father extends Component {
constructor() {
super();
this.state = {
name : "kaso"
}
}
render() {
return(
<div>
<Son data = { this.state } />
</div>
)
}
}
super
原型继承,将this指向该对象- constructor自动传入
props
data = { this.state }
分发下去
class Son extends Component {
return(
<h1>{ this.props.data.name }</h1>
)
}
this
指代super
的对象props
为对象名data
为传入参数