0

When I download a react project, my default in App.js is :

function App()

However, a lot of YouTube tutorials uses:

class App extends React.Component {

Is there a difference between the two? Is one just older?

rickandmorty
  • 165
  • 2
  • 8
  • 2
    They are 2 different ways of creating react components, class is the more traditional way and used to be the primary way, functions are the more modern way and got more useful in the last 1-2 years so they are getting more popular. – Shmili Breuer Mar 22 '21 at 21:14
  • Maybe this can help you: https://stackoverflow.com/questions/36097965/when-to-use-es6-class-based-react-components-vs-functional-es6-react-components – Girgetto Mar 22 '21 at 21:20

1 Answers1

3

Functional components have somewhat replaced class components because they generate less output code. Previously, classes were used to be able to use the state. However, this is now possible with the useState hook.

Bart Krakowski
  • 1,655
  • 2
  • 8
  • 25