猿问

在 React 项目中配置 ESLint 后在箭头函数中抛出错误

我正在做一个 React 项目,我在我的项目中配置了 ESLint。在该配置之后,我得到了我在图片中提到的错误:

为什么 ESLint 会抛出这个错误以及如何解决这个问题?



呼啦一阵风
浏览 143回答 5
5回答

一只名叫tom的猫

在 loginError 之前添加类型 ...例如:const loginError = props => { ... }var loginError = props => { ... }

ibeautiful

您需要使用 或 声明loginError箭头var let函数const。

海绵宝宝撒

查看错误处理。try&catch功能更简洁的代码

慕丝7291255

你应该用 const 声明函数。const loginError = props => {   ...   }

慕码人8056858

基本上你应该得到'loginError is not defined',如果那是 lint,但这个错误是针对最新的 ES6 的。我的 eslintrc.json 是{&nbsp; &nbsp; "parser": "babel-eslint",&nbsp; &nbsp; "env": {&nbsp; &nbsp; &nbsp; &nbsp; "browser": true,&nbsp; &nbsp; &nbsp; &nbsp; "es6": true&nbsp; &nbsp; },&nbsp; &nbsp; "extends": [&nbsp; &nbsp; &nbsp; &nbsp; "plugin:react/recommended",&nbsp; &nbsp; &nbsp; &nbsp; "standard",&nbsp; &nbsp; &nbsp; &nbsp; "eslint:recommended"&nbsp; &nbsp; ],&nbsp; &nbsp; "globals": {&nbsp; &nbsp; &nbsp; &nbsp; "Atomics": "readonly",&nbsp; &nbsp; &nbsp; &nbsp; "SharedArrayBuffer": "readonly"&nbsp; &nbsp; },&nbsp; &nbsp; "parserOptions": {&nbsp; &nbsp; &nbsp; &nbsp; "ecmaFeatures": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "jsx": true&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; "ecmaVersion": 2018,&nbsp; &nbsp; &nbsp; &nbsp; "sourceType": "module"&nbsp; &nbsp; },&nbsp; &nbsp; "plugins": [&nbsp; &nbsp; &nbsp; &nbsp; "react"&nbsp; &nbsp; ],&nbsp; &nbsp; "rules": {&nbsp; &nbsp; },&nbsp; &nbsp; "settings": {&nbsp; &nbsp; &nbsp; &nbsp; "react": {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "createClass": "createReactClass", // Regex for Component Factory to use,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// default to "createReactClass"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "pragma": "React",&nbsp; // Pragma to use, default to "React"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "version": "detect", // React version. "detect" automatically picks the version you have installed.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// default to latest and warns if missing&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// It will default to "detect" in the future&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "flowVersion": "0.53" // Flow version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "propWrapperFunctions": [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "forbidExtraProps",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {"property": "freeze", "object": "Object"},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {"property": "myFavoriteWrapper"}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "linkComponents": [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Components used as alternatives to <a> for linking, eg. <Link to={ url } />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Hyperlink",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {"name": "Link", "linkAttribute": "to"},&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {"name": "a", "linkAttribute": "href"}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; }}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答