Why is ESLint rejecting this?
let myFunc = (state) => {a:"b"};
It is saying that it expected a function or assignment call.
Why is ESLint rejecting this?
let myFunc = (state) => {a:"b"};
It is saying that it expected a function or assignment call.
In ES6 arrow functions
If you use curly braces {}
, you should return with a return
statement.
let myFunc = (state) => {
return { a:"b"}
}
If you use don't use braces, you should enclose the return object with round braces ()
.
let myFunc = (state) => ({ a:"b"})
An arrow function returning an object literal in this way is syntactically ambiguous, as it could also be a JavaScript block with the label a
in it. You need to surround the literal with parens to make it clear:
let myFunc = (state) => ({a:"b"});