gpt4 book ai didi

javascript - 类型错误 : undefined is not an object (evaluating 'this.setState' )

转载 作者:行者123 更新时间:2023-11-30 08:23:01 26 4
gpt4 key购买 nike

<分区>

我一直收到这个错误,我不知道为什么,因为我尝试过的所有方法都不起作用。有谁知道为什么这不起作用以及它如何起作用?

我在这里得到这个未定义的:

this.setState({isAuthenticated: true})

这是我的代码:

class Login extends Component{

constructor(props){
super(props);

this.state ={
email: '',
password: '',
isAuthenticated: false
};

function login(username, email){
sessionStorage.setItem('loginSessionUsername', username);
sessionStorage.setItem('loginSessionEmail', email);
this.setState({isAuthenticated: true})
}
}

render(){
const isAuthenticated = this.state.isAuthenticated;
if(isAuthenticated){
return(
<div>
<Servicedesk />
</div>
)
}
return(
<div id='Login' className='setVisible'>
<div>
<label>Emailadres</label>
<input type='text' placeholder='je email' onChange={ev => this.setState({email: ev.target.value})}/>
<label>Wachtwoord</label>
<input type='password' placeholder='je wachtwoord' onChange={ev => this.setState({password: ev.target.value})}/>
<br />
<button onClick={(event => this.handleClick(event))}>Submit</button>
</div>
</div>
)
}
}

export default Login;

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