I swa this arrow function in a Redux example:
export const addTodo = (text) => {
return {
type: 'ADD_TODO',
id: nextTodoId++,
text
}
}
I was wondering whether I can get rid of the extra layer of { return ...; }
, essentially getting rid of the block?
For illustration, the following two arrow functions are the same:
const fn = (a) => a + 1;
const fn = (a) => { return a+1; };
and I can strip the return
from the second, more verbose version.
But when I do the same to the Redux example and strip the return layer, I get an error:
SyntaxError: repl, unexpected token, expected ; ...
It seems that there is some confusion between the {}
in the object literal and code blocks. Is there a way to remove this this extra layer of return here?