class App extends React.Component {
constructor(props){
// 必须要传递参数
super(props)
this.state = {
text: this.props.text
}
}
render() {
return (
// render不用传props
<div>{this.props.children}</div>
)
}
}
constructor和render内部this都指向组件实例,只要constructor内部要读取props就要写明这个参数,但是render不用,为什么呢?
噜噜哒
相关分类