期望赋值或函数调用,却看到了一个表达式.eslintno-unused-expressions [英] Expected an assignment or function call and instead saw an expression.eslintno-unused-expressions
本文介绍了期望赋值或函数调用,却看到了一个表达式.eslintno-unused-expressions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在函数中使用了三元运算符.但是 eslint 在这方面抛出了错误.请帮我解决这个问题.
Hi I am using a ternary operator inside a function. But eslint throws error on this. Pls help me to fix this.
const Test = (showBtn, bubbleId, latitude, longitude, zoom, drillLevel) => {
setShowBtn(showBtn);
drillLevel === 'area' ? getCitiesData(bubbleId) : getStatesData();
setViewport({
...viewport,
latitude,
longitude,
zoom,
});
};
推荐答案
如果您当前的代码有效,那么完全避免使用条件运算符并使用 if
/else 可能更合适
代替:
If your current code works, it would probably be more appropriate to avoid the conditional operator entirely and use if
/else
instead:
if (drillLevel === 'area') getCitiesData(bubbleId)
else getStatesData();
这样,您实际上没有任何未使用的表达式,这是修复此类 linter 警告的正确方法.
This way, you don't actually have any unused expressions, which is the right way to fix this sort of linter warning.
这篇关于期望赋值或函数调用,却看到了一个表达式.eslintno-unused-expressions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文