[英]How to fix this Eslint warning in reactjs
I'm a beginner and I read the Eslint docs but cant understand how to refactor my code so the warning go away.我是初学者,我阅读了Eslint 文档,但不明白如何重构我的代码,所以警告 go 消失了。
Here's an image:这是一张图片:
The code is basically simple: and at authUser.roles.includes(ROLES.A...
the warning comes!代码基本上很简单:在
authUser.roles.includes(ROLES.A...
警告来了!
Please advice!请指教!
function onClick() {
const { authUser } = props;
authUser.roles.includes(ROLES.ANON) ? openSignin() : openDashboard();
}
function openSignin() {
props.showDash({
open: true,
closeDashboard,
});
}
function openDashboard() {
navigate('/app/dashboard', { replace: true });
}
return (
<div>
<Button className="button is-large" onClick={onClick}>
<span className="icon is-medium">
<i className="fas fa-user" />
</span>
</Button>
</div>
);
Ternary expressions are for assignment.三元表达式用于赋值。 But you're not assigning to anything.
但是你没有分配任何东西。
Swich to切换到
if (authUser.roles.includes(ROLES.ANON)) {
openSignin();
} else {
openDashboard();
}
You can disable the rule in your config file , disable the rule on the top of the page您可以在配置文件中禁用该规则,在页面顶部禁用该规则
/* eslint no-unused-expressions: "off" */
or you can disable it for one line或者你可以为一行禁用它
code // eslint-disable-line no-unused-expressions
or或者
// eslint-disable-next-line no-unused-expressions
Note: no-unused-expressions
is the error that you are getting注意:
no-unused-expressions
是您得到的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.