7

Used to be:

class App extends Components{
  //...
}

Now create-react-app has this in App.js:

function App(){
  //...
}

Anyone know why this change was made? Are they suggesting we shouldn't have state in App?

simhumileco
  • 31,877
  • 16
  • 137
  • 115
Jona
  • 1,023
  • 2
  • 15
  • 39

2 Answers2

9

Since the introduction of hooks in React, you can have state in a function component (cf. useState).

According to React 16.x roadmap post, it might be a good move to slowly transition class components to function components:

Hooks don’t deprecate classes. However, if Hooks are successful, it is possible that in a future major release class support might move to a separate package, reducing the default bundle size of React.

Mick F
  • 7,312
  • 6
  • 51
  • 98
  • 3
    actually they are called **function** components, not functional components. Class components also tend to be functional in some cases, and even though they are classic components nobody calls them classical ;) – marzelin Apr 28 '19 at 12:04
0

The class Components were not very reusable, and they were lacking a sense of interchangeability. It will be ideal to use move away from class components and start using function components. refer to this post

Invincible
  • 1,418
  • 18
  • 23