简体   繁体   English

Javascript ESLint错误-条件表达式中不必要使用布尔文字

[英]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.

相关问题 Eslint:在条件表达式中不必要使用布尔文字 - Eslint: Unnecessary use of boolean literals in conditional expression 错误:在条件表达式中不必要地使用布尔文字 - Error: Unnecessary use of boolean literals in conditional expression 错误在条件表达式中不必要地使用布尔文字 no-unneeded-ternary - error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary 在条件表达式中不必要地使用 Boolean 文字 - Unnecessary use of Boolean literals in conditional expression Javascript:错误在条件表达式 no-unneeded-ternary 中不必要地使用 boolean 文字 - Javascript: error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary 修复 eslint 错误 - 调用 require() 应使用字符串文字 - fixing an eslint error - Calls to require() should use string literals 为何使用!! 将变量强制转换为布尔值以用于条件表达式? - Why use !! to coerce a variable to boolean for use in a conditional expression? 如何在条件中更改表达式的求值以检查Javascript中的布尔值? - How do I change the evaluation of the expression in the conditional to check for a boolean in Javascript? 不使用关系运算符的 JavaScript 条件表达式 - JavaScript Conditional expression without the use of Relational operator 在循环中使用JavaScript regexp文字会消耗不必要的内存吗? - Does using JavaScript regexp literals in loops consume unnecessary memory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM