gpt4 book ai didi

javascript - react 类 : setState does nothing (and no errors reported)

转载 作者:行者123 更新时间:2023-11-30 09:30:55 24 4
gpt4 key购买 nike

<分区>

我有一个带有这个构造函数的 React 类:

class AddList extends Component {
constructor(props){
super(props);
this.state = { hidden: true };
}

然后我有这个功能:

handleSubmit(e) {
e.preventDefault(); // this prevents the page from reloading -- do not delete this line!

// Implement the rest of this function here!
alert('this.state.hidden: ' + this.state.hidden);
if (this.state.hidden == true){
alert('setting hidden to false');
this.setState({hidden: false});
}
else{
alert('setting hidden to true');
this.setState({hidden: true});
}
alert('this.state.hidden: ' + this.state.hidden);
. . .

My problem is that neither this.setState({hidden: false);
nor this.setState({hidden: 'false');

改变状态!“警告”框确认通过代码的路径,只有“setState”似乎是 NOP!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com