首页 > 解决方案 > 当按钮被禁用时,如何显示消息或警告模式?

问题描述

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;
}

上述代码显示超出最大更新深度错误。

标签: javascriptreactjs

解决方案


您可以在不调用函数的情况下这样做。

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 }

推荐阅读