如何避免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)
当只有一个参数时,ES6中参数与箭头函数的括号是可选的,但ESLint默认会抱怨这一点。这是由arrow-parens选项控制的。
要么更改此选项,要么更改箭头功能以使用(c)
而不是c
作为参数列表。