Stateless component as a function or a const

Viewed 814

I'm aware of the benefits, of making a component stateless. What I'm not aware of is - what's the difference between making the component as a const or a function. I'm a bit confused, because I've seen several examples, using both.

function MyComponent(props) {
  return(
    <div>Hello world</div>
  )
}

vs.

const MyComponent = (props) => {
  return(
    <div>Hello world</div>
  )
}

Would be great with an explanation what to choose correctly

1 Answers

In this case for a stateless component definition there's no difference, you can do it either way, there's no right or wrong... however in my opinion is becoming more standard to define the components with arrow function, it probably looks more elegant as well.

const MyComponent = (props) => {
  return(
   <div>Hello world</div>
  )
}
Related