What is the difference between
const layout = (props) => ();
and
const layout = (props) => {};
on React framework?
What is the difference between
const layout = (props) => ();
and
const layout = (props) => {};
on React framework?
That's not really a React
behavior, but it's how JS and arrow functions work. By using this syntax () => ()
you are telling JS to return the value between parenthesis (without the need for an explicit return
:
const a = () => ('returned value')
const b = () => {'returned value'}
console.log(a()) // 'returned value'
console.log(b()) // undefined
so using const a = () => ('returned value')
is the same as doing:
const a = () => {
return 'returned value'
}