javascript - 当按钮被禁用时,如何显示消息或警告模式?
问题描述
disabled={this.state.user_type.title === "" || this.checkDuplicateUserType()}
checkDuplicateUserType = () => {
let val = this.props.userTypes.includes(this.state.user_type.title.toLowerCase())
if(val === true) {
this.setState({warningModal:true})
return val;
}
return val;
}
上述代码显示超出最大更新深度错误。
解决方案
您可以在不调用函数的情况下这样做。
componentDidMount() {
let val = this.props.userTypes.includes(this.state.user_type.title.toLowerCase())
this.setState({ warningModal: val })
}
你的残疾状况是这样的
disabled = { this.state.user_type.title === "" || this.state.warningModal }
推荐阅读
- amazon-dynamodb - Alexa Skill 中的 Dynamo DB 排行榜
- java - Java - 读取文件后删除文件
- node.js - 在数字海洋液滴上找不到 nodemon 实例
- python - 错误:命令错误退出状态
- python - 为什么 Python 在使用线程时会启动许多进程
- android - Android kotlin 在某些片段中显示导航抽屉图标而不是后退按钮
- pine-script - 如何编写一个简单的 pine 脚本来绘制投资组合余额
- algorithm - 找到大小为 k 的子序列,使得值之间的最小距离最大
- apache-kafka - ClickHouse:在分布式和复制表中使用 hash 和 internal_replication
- r - 闪亮模块中的观察事件问题