反応クラスベースのコンポーネントの小道具に基づいて状態を更新しようとしていますが、エラーが発生します
TypeError:オブジェクト '#'の読み取り専用プロパティ 'statusKnown'に割り当てることができません
これが以下のコードです
componentDidMount(){
this.calClass()
}
calClass = () => {
console.log(this.props.statusKnown, this.state.active);
if (this.props.statusKnown == "deactive") this.setState({ active: false });
else if ((this.props.statusKnown = "active")) this.setState({ active: true });
};
次に親コンポーネントで
<Button item={item} categoryID={categoryID} statusKnown={status}/>;
反応がこれを許可しない場合、これに対する可能な解決策は何ですか?
あなたはいくつかの=
兆候を見逃しました。常に使用する必要があります===
componentDidMount(){
this.calClass()
}
calClass = () => {
console.log(this.props.statusKnown, this.state.active);
if (this.props.statusKnown === "deactive") this.setState({ active: false });
else if ((this.props.statusKnown === "active")) this.setState({ active: true });
};
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加