[英]Javascript ESLint Error - Unnecessary use of boolean literals in conditional expression
Currently have an issue with respect to ESLint picking up an error with ternery operators which is 目前对于ESLint遇到实习生错误的问题是
Unnecessary use of boolean literals in conditional expression.
在条件表达式中不必要地使用布尔文字。
My code is as follows: 我的代码如下:
<div style={style}><DatePicker label="From" disabled={value === 'custom' ? true : false} /></div>
<div style={style}><DatePicker label="To" disabled={value === 'custom' ? true : false } /></div>
What is the best way to write this to prevent ESLink picking up the following error. 编写此代码以防止ESLink收到以下错误的最佳方法是什么。
Simply write disabled={value === 'custom'}
. 只需编写
disabled={value === 'custom'}
。
value === 'custom'
will already return true or false, no need to test if true then return true. value === 'custom'
将已经返回true或false,无需测试是否为true,然后返回true。 ;-) ;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.