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?

2
  • Functional components that use hooks rather than classes are the new thing now. Commented Sep 21, 2019 at 4:39
  • Yes, but that doesn't relate to what I was asking, which was why a regular function rather than an arrow function component. Commented Sep 22, 2019 at 5:12

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.