javascript - 在某些情况下无法关闭反应模式
问题描述
您好,我想在满足条件时关闭模态(this.chooseRounds > 0 && this.state.rounds == this.state.roundsValue)
,但我无法关闭,我不知道为什么。我花了更多时间来解决这个问题,这是一个代码:
let modalShow;
if(this.chooseRounds > 0 && this.state.rounds == this.state.roundsValue) {
modalShow = (
<ReactModal
isOpen={true}
contentLabel="Minimal Modal Example"
ariaHideApp={false}
>
<button onClick={this.handleModal}>Close Modal</button>
</ReactModal>
);
}else {
modalShow = (
<ReactModal
isOpen={false}
contentLabel="Minimal Modal Example"
ariaHideApp={false}
>
<button onClick={this.handleModal}>Close Modal</button>
</ReactModal>
)
}
在状态下我有showModal: false,
handleModal函数里面有this.setState({ showModal: !this.state.showModal });
解决方案
您需要使用您的 showModal 状态并将其放入 isOpen 道具中
const { showModal } = this.state
<ReactModal
isOpen={showModal}
contentLabel="Minimal Modal Example"
ariaHideApp={false}
>
<button onClick={this.handleModal}>Close Modal</button>
</ReactModal>
推荐阅读
- php - 从 URL 获取 Instagram 用户名 - 使用正则表达式忽略句点
- microsoft-graph-api - 即使驱动器存在,也无法检索用户的 mysite URL
- pandas - Pandas - 使用空格
- .net - 嵌入 PowerBI 报表服务器报表时处理身份验证
- c - ZooKeeper 3.4.12 C 客户端无法连接到 Solaris11 机器上的 ZooKeeper 服务器
- jekyll - 如何按作者对帖子进行分页
- terraform - 在处理完所有资源后使用专用端点应用更改
- html - 如何从输入文本字段将新数据插入条形图中?
- macos - SerpentAI 安装错误
- angular - 自定义标题 Ag-Grid 中的排序数字?