-1

What is the difference between

const layout  = (props) => ();

and

const layout = (props) => {};

on React framework?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Fahim.ga
  • 1
  • 1
  • 1
    And fundamentally I would really recommend knowing the basics of JS/ES6 before trying to add React on top. – jonrsharpe Jun 10 '22 at 12:31
  • When you use `{}` that means you have to use `return` keyword to render a `JSX` element in react component. However, if you use `()` you don't need `return` keyword because it will by default return the component. However if you use `()` you can't use normal javascript because it returns directly – Shubham Waje Jun 10 '22 at 12:39
  • Thanks a lot man, that's helps me very good. – Fahim.ga Jun 10 '22 at 17:17

1 Answers1

0

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'
}
Toni Bardina Comas
  • 1,670
  • 1
  • 5
  • 15