我只是检查此条件以在元素上设置类,但收到此错误:
<div className={(this.state.kindValue === 1 && this.state.depositValue === 1) || (this.state.depositValue === 0 ? 'two fields' : 'two fields hide')}>
index.js:1406 Warning: Received
true
for a non-boolean attributeclassName
.If you want to write it to the DOM, pass a string instead: className="true" or className={value.toString()}.
我不明白我应该怎么解决这个问题?
最佳答案
我认为您错误地放置了括号,因此您得到的是 true
或 false
而不是 两个字段
或 两个字段隐藏
。尝试使用此代码
<div className={(this.state.kindValue === 1 && this.state.depositValue === 1) || this.state.depositValue === 0 ? 'two fields' : 'two fields hide'}>
关于javascript - React 收到非 bool 属性的 `true`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60014748/