简体   繁体   English

如何在 reactjs 中修复此 Eslint 警告

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

相关问题 如何解决这个 Reactjs Eslint 关于 &#39;index&#39; 的警告已定义但从未使用 - How to solve this Reactjs Eslint warning about 'index' is defined but never used 如何修复以避免 React 中的 ESLint Effect 回调警告 - How to fix to avoid ESLint Effect callbacks warning in React 我应该如何修复 eslint 警告(React Hook useEffect 缺少依赖项)和由警告引起的循环? - How should I fix eslint warning (React Hook useEffect has a missing dependency) and a loop caused by the warning? 如何修复类方法将使用的“警告预期”“这个”“eslint”错误? - How can I fix 'warning Expected 'this' to be used by class method ' eslint error? 如何使用eslint-plugin-react来修复由Flow Function Types引起的警告? - How to fix warning caused by Flow Function Types using eslint-plugin-react? 如何在 reactjs 中禁用 eslint 检查开发模式 - How to disable eslint check on development mode in reactjs 如何修复“index.js:1446 警告:无法在未安装的组件上调用 setState(或 forceUpdate)...”在 ReactJS 中 - How to fix 'index.js:1446 Warning: Can't call setState (or forceUpdate) on an unmounted component..." in ReactJS 与reactjs、material ui一起使用时如何修复未知道具zdepth警告? - how to fix unknown prop zdepth warning when using with reactjs , material ui? 如何解决reactjs警告:数组中的每个子元素都应具有唯一的属性……? - How to fix reactjs warning: each child in an array should have a unique prop…? 如何修复 eslint 警告 JSX 属性值不应包含在同一 scope react-perf/jsx-no-new-function-as-prop 中创建的函数 - How to fix eslint warning warning JSX attribute values should not contain functions created in the same scope react-perf/jsx-no-new-function-as-prop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM