Skip to content
Advertisement

What is the difference between react: class vs function App()?

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement