【问题标题】:React received `true` for a non-boolean attributeReact 收到一个非布尔属性的 `true`
【发布时间】:2020-05-17 18:20:23
【问题描述】:

我只是检查这个条件来设置一个元素的类,但是得到这个错误:

<div className={(this.state.kindValue === 1 && this.state.depositValue === 1) || (this.state.depositValue === 0 ? 'two fields' : 'two fields hide')}>

index.js:1406 警告:收到true 的非布尔属性 className.

如果要将其写入 DOM,请改为传递字符串: className="true" 或 className={value.toString()}。

我不明白我应该如何解决这个问题?

【问题讨论】:

    标签: javascript reactjs jsx


    【解决方案1】:

    我认为你把括号放错了,所以你得到truefalse 而不是two fieldstwo fields hide。试试这个代码

    <div className={(this.state.kindValue === 1 && this.state.depositValue === 1) || this.state.depositValue === 0 ? 'two fields' : 'two fields hide'}>
    

    【讨论】:

      猜你喜欢
      • 2021-05-10
      • 1970-01-01
      • 2019-09-21
      • 2023-02-09
      • 2019-08-18
      • 2022-10-09
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      相关资源
      最近更新 更多