0

Now (since early this year) when you bootstrap a React app with Create React App, it now generates a function component rather than a class component:

function App() {
  // ...
}

I'm wondering why they didn't instead use an arrow function component, given ES6 arrow functions have been out for a while, plus you don't have to bind this:

const App() => {
  // ...
};

Are there any notable disadvantages to using an arrow function component instead that might've led them to make that decision, or was it simply that that syntax is more familiar?

nCardot
  • 5,992
  • 6
  • 47
  • 83
  • Functional components that use [hooks](https://reactjs.org/docs/hooks-intro.html) rather than classes are the new thing now. – Herohtar Sep 21 '19 at 04:39
  • Yes, but that doesn't relate to what I was asking, which was why a regular function rather than an arrow function component. – nCardot Sep 22 '19 at 05:12

2 Answers2

2

They use regular functions to keep it consistent with the react documentation.

Source: https://github.com/facebook/create-react-app/pull/6655

plus you don't have to bind this

Not really a benefit here, since this doesn't get used in functional components.

Nicholas Tower
  • 72,740
  • 7
  • 86
  • 98
0

As I know, in the next versions there will be a performance difference between class and function components, so that's why they are changing to function, about arrow function, I like it more than regular functions as you said there are no need to bind in it, but there are few things that you shouldn't use arrow in them, you can read them from here. So that's maybe because of these reasons.hope it helps

behzad
  • 801
  • 3
  • 15
  • 33