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)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With