围绕箭头函数参数的预期括号。 (箭头的括号)

问题描述 投票:-2回答:1

如何避免ES7箭头功能上的Flow类型错误

 handleSelectCategory = (e) => {
        const { form } = this.state;

        let newCategories = [];
        if (form.categories.findIndex(c => c.value === e.value) >= 0) {
          newCategories = form.categories.filter(c => c.value !== e.value);
        } else {
          newCategories = [...form.categories, e];
        }
        this.setState({ form: Object.assign({}, form, { categories: newCategories }) });
      }

我收到了警告

Expected parentheses around arrow function argument. (arrow-parens)
javascript reactjs eslint
1个回答
1
投票

当只有一个参数时,ES6中参数与箭头函数的括号是可选的,但ESLint默认会抱怨这一点。这是由arrow-parens选项控制的。

要么更改此选项,要么更改箭头功能以使用(c)而不是c作为参数列表。

© www.soinside.com 2019 - 2024. All rights reserved.