Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does create-react-app now use a function component for 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?

like image 647
Jona Avatar asked Apr 28 '19 11:04

Jona


People also ask

Is create React app obsolete?

Please note that global installs of create-react-app are no longer supported. You can fix this by running npm uninstall -g create-react-app before using create-react-app again.

Why not to use create React app in production?

However, it is not created for production. Unfortunately, devs have been using it for all their projects. CRA limits your ability to change any configurations, it has tons of unneeded dependencies, you can't customize configurations, you can't build microfrontends …

What is the difference between functional component and class component?

A functional component is just a plain JavaScript pure function that accepts props as an argument and returns a React element(JSX). A class component requires you to extend from React. Component and create a render function which returns a React element. There is no render method used in functional components.

Why does create React app use node?

ReactJS uses Node. js, a JavaScript runtime, to build your JavaScript code. Basically, the ReactJS is a JavaScript framework which needs the help of node js and npm(Package manager) to tell the native side(Android/iOS) that these are packages I need to run my app. And it adds all the dependencies needed to run the app.


1 Answers

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.

like image 84
Dirty Henry Avatar answered Sep 28 '22 22:09

Dirty Henry