gpt4 book ai didi

node.js - 状态未在render()组件中更新

转载 作者:行者123 更新时间:2023-12-03 12:34:18 25 4
gpt4 key购买 nike

我对JS的 react 非常陌生,现在我正在使用它来构建应用程序。我有个问题。

在Button Click事件中,我具有如下代码逻辑:

handlestartbutton(event) {
const accesskey = localStorage.getItem(localStorageKeys.accessTokenKey);
const decodedAccessKey = jwt_decode(accesskey);
const date = dateConverter.epochToReadableDate(decodedAccessKey.exp);
if (date.currentTime < date.expiryDate) {
this.setState({
accesstokenexpirydate: true
}, () => {
if(this.state.accesstokenexpirydate === false) {
//rest of the code

}
})

在renderer()中,我有一个弹出的用户界面,如下所示:
renderer()
{
{this.state.accesstokenexpirydate === true ? (
<Popup
open ={this.state.open}
closeOnDocumentClick={false}
closeOnEscape={false}
onClose={this.closeModal}className
>
<div className={popstyles.popupBody}>
<div className={popstyles.modalClose}>
<a className="close" onClick={this.closeModal}>
&times;
</a>
{""}
<div className ={popstyles.unAutherizedUser}>
<label >{homeConstantMessages.accessTokenExpire}</label>
<div className ={popstyles.unAutherizedUserMsg}>
<label>{homeConstantMessages.accessTokenExpireMsg}</label>
<button className ={styles.refreshaccessbtn} onClick = {this.navigateToHomePage.bind(this)} label = {homeConstantMessages.refreshbtn}>
</button>
</div>
</div>
</div>
</div>
</Popup>
) : (
''
)}
}

问题是,即使状态变量accesstokenexpirydate设置为true,单击第一次启动按钮时也不会弹出此弹出UI。第二次单击该按钮时,将弹出UI。有人可以帮我吗

最佳答案

1)我认为您必须应用如下箭头功能,然后才能使用 this

handlestartbutton=(event)=> {...}

2)我对名称感到很困惑,难道您不认为它应该是 render(...)而不是 renderer()

关于node.js - 状态未在render()组件中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58967684/

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