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?
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?
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.
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