初學react、請教一下,為什么用函數(shù)的寫法寫組件props就會報錯,用類寫的組件就是可以的
//正確 class?TodoItem?extends?React.Component{ ????????render(){ ????????????????return( ????????????????????<div>{this.props.content}</div> ????????????????) ????????} } //錯誤(這個寫法是現(xiàn)在版本腳手架示例里面的) function?TodoItem?(){ ?return( ????????????????????<div>{this.props.content}</div> ????????????????) }
????
2019-06-26
函數(shù)組件的props是用傳入的參數(shù)來表示的。
function TodoItem(props) {
return (
????<div>{props.content}</div>
)
}