eslint抱怨简单的React Reducer中的传播算子

时间:2020-07-22 18:11:32

标签: javascript reactjs ecmascript-6 eslint

我有一个非常简单的React Reducer,而eslint抱怨我如何传播状态。下面是代码。我希望那可以。我也在下面粘贴我的.eslintrc。

function quizReducer(state, action) {
  switch (action.type) {
    case RESET_QUIZ:
      return {
        ...state,
        currentQuestion: 0,
        currentAnswer: '',
      }
    default:
      return state
  }
}

eslintrc

{
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "destructuring": true,
      "spread": true,
      "experimentalObjectRestSpread": true
    }
  },
  "plugins": ["react-hooks"],
  "rules": {
    //additional rules here
    "react-hooks/rules-of-hooks": "error"
  }
}

错误在...状态行上,并且是

ESLint: Parsing error: Unexpected token ...

2 个答案:

答案 0 :(得分:1)

尝试从eslintrc中删除行,在“ jsx”之后:true,您应该获得以下内容:

"parserOptions": {
  "ecmaVersion": 2020,
  "ecmaFeatures": {
    "jsx": true
  }
}

答案 1 :(得分:1)

在ESLint 5.0.0版中,the experimentalObjectRestSpread option was deprecated

尝试从ecmaFeatures除去jsx之外的所有选项。还要将ecmaVersion至少更改为2018或版本9(或更高版本),如同一链接所述。

    "ecmaVersion": 2018, // or 9
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
    }