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)
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)
Share
Improve this question
edited Jun 25, 2021 at 8:01
thelovekesh
1,4521 gold badge9 silver badges22 bronze badges
asked Sep 15, 2018 at 13:41
aliali
1511 gold badge2 silver badges5 bronze badges
2
|
1 Answer
Reset to default 17Parentheses 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.
'arrow-parens': ['error', 'as-needed'],
on vscode – Yogi Arif Widodo Commented Oct 26, 2022 at 22:43