如何在 reactjs 中修复此 Eslint 警告
How to fix this Eslint warning in reactjs
我是初学者,我阅读了 Eslint docs 但无法理解如何重构我的代码以便警告消失。
这是一张图片:
代码基本上很简单:在 authUser.roles.includes(ROLES.A...
处出现警告!
请指教!
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>
);
三元表达式用于赋值。但是你没有分配给任何东西。
切换到
if (authUser.roles.includes(ROLES.ANON)) {
openSignin();
} else {
openDashboard();
}
您可以在config file中禁用规则,在页面顶部禁用规则
/* eslint no-unused-expressions: "off" */
或者您可以将其禁用一行
code // eslint-disable-line no-unused-expressions
或
// eslint-disable-next-line no-unused-expressions
注意:no-unused-expressions
是您遇到的错误
我是初学者,我阅读了 Eslint docs 但无法理解如何重构我的代码以便警告消失。
这是一张图片:
代码基本上很简单:在 authUser.roles.includes(ROLES.A...
处出现警告!
请指教!
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>
);
三元表达式用于赋值。但是你没有分配给任何东西。
切换到
if (authUser.roles.includes(ROLES.ANON)) {
openSignin();
} else {
openDashboard();
}
您可以在config file中禁用规则,在页面顶部禁用规则
/* eslint no-unused-expressions: "off" */
或者您可以将其禁用一行
code // eslint-disable-line no-unused-expressions
或
// eslint-disable-next-line no-unused-expressions
注意:no-unused-expressions
是您遇到的错误