Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get class declarations from create-react-app?

After creating a new react project using npx create-react-app new I'm getting functional js code in App.js:

import React from 'react';
import './App.css';

//need to have a class instead of a function here:
function App() {

  return (
    <div className="App">
    </div>
  );
}

export default App;

What command do I need to create a none functional react project? If functional is better than none functional please explain why.

like image 522
Kirill Avatar asked Jan 02 '23 00:01

Kirill


1 Answers

If you have install create-react-app for this project, then it is come up with all the new features from react 16.8.6 (latest version of react). The latest react version come up with concept of Hooks. That is why we are getting functional component by default instead of class based component to increase the performance.

If you want class based component by default they you have to come up with older version of create-react-app. Ref

like image 128
ravibagul91 Avatar answered Jan 08 '23 00:01

ravibagul91