箭头函数参数周围应有圆括号。(箭头-括号) [英] Expected parentheses around arrow function argument. (arrow-parens)

查看:0
本文介绍了箭头函数参数周围应有圆括号。(箭头-括号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免ES7箭头函数出现流类型错误

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作为参数列表。

这篇关于箭头函数参数周围应有圆括号。(箭头-括号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆