我是新來的react.js,我試圖math.random一個數字並把它放在this.props.firstCard屬性中,但它返回undefined。我嘗試了一些變量,但只有結果是未定義的或語法錯誤。代碼:this.props.firstCard返回undefined
handleClick() {
let firstCard = this.state.isFirstCardChosen;
function chooseCard() {
return Math.floor(Math.random() * (80 - 1) + 1);
}
if (firstCard == false) {
this.props.firstCard = chooseCard;
console.log(this.props.firstCard);
}
}
有什麼不對的呢?提前致謝。
SRY出現了一個'this.props.firstCard == chooseCard;'而不是「this.props.firstCard = chooseCard;」 ,它返回'不可擴展'的錯誤。 – zaebalo
this.props是不可變的。你不能修改它。通過一些關於setState的反應教程和道具 –