Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected parentheses around arrow function argument. (arrow-parens)

How to avoid Flow-type error on an ES7 arrow function

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 }),
  });
};

I receive the warning

Expected parentheses around arrow function argument. (arrow-parens)
like image 696
ali Avatar asked Sep 15 '18 13:09

ali


People also ask

Do arrow functions need parentheses?

Table of Contents. Arrow functions can omit parentheses when they have exactly one parameter. In all other cases the parameter(s) must be wrapped in parentheses. This rule enforces the consistent use of parentheses in arrow functions.

Can we pass arguments in arrow function?

There are differences between arrow functions and traditional functions, as well as some limitations: Arrow functions don't have their own bindings to this , arguments or super , and should not be used as methods. Arrow functions don't have access to the new.target keyword.

Do arrow functions always require an argument?

Arrow functions do not have an arguments binding. However, they have access to the arguments object of the closest non-arrow parent function. Named and rest parameters are heavily relied upon to capture the arguments passed to arrow functions.

What does an arrow function return?

Arrow functions with curly brackets are the only way to get multiple statements or expressions inside the function body. The return statement stops the execution of a function and will return a value from the function.


1 Answers

Parentheses around the parameter to an arrow function are optional in ES6 when there's only one argument, but ESLint complains about this by default. This is controlled by the arrow-parens option.

Either change this option, or change your arrow functions to use (c) instead of c as the parameter lists.

like image 191
Barmar Avatar answered Sep 30 '22 06:09

Barmar