关于Props的问题
来源:5-4 深入了解React(React组件)
wykun
2018-04-24
class Title extends React.Component {
//constructor(props) {
// super(props)
//}
render() { // 括号中props不写
return <h1>{this.props.name}{this.props.children}</h1>
}
}
class App extends React.Component {
render() {
return (
<div>
<Title name='title test'>
<p>link</p>
</Title>
<hr/>
<Component/>
</div>
)
}
}请问老师.我在Title组件中我的constructor和props都不写而我也能将props成功显示出来,那么这个是不是不写也行啊.但是super()方法不是为了将this指向继承的类吗..请老师指点..
写回答
2回答
-
不用this的话可以不写,但稍微有点逻辑的都会用到
10 -
慕莱坞6170871
2019-11-29
只有 constructor 里面需要用到 this.props的时候需要
00
相似问题