[英]IntelliJ shows this.props is undefined while console.log suggests otherwise
[英]console.log(this.props) undefined
在我的代碼中,當我未定義時,我在 componentDidMount 中使用了 console.log(this.props)。 我在 render() 中的 console.log(this.props) 我得到了四個輸出,前兩個所有屬性都未定義,后兩個是正確的。
componentDidMount = () => {
const { ratingsAverage } = this.props;
console.log(ratingsAverage);
//this.setState({value: this.props.ratingsAverage})
}
render() {
console.log(this.props);
}
componentDidMount() 中 console.log(ratingsAverage) 的 output 未定義。
render() 中 console.log(this.props) 的 output 如下圖所示
嘗試這個。 你的組件構造函數應該是這樣的
constructor(props){
super(props);
this.state = {
//states
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.