Search code examples
reactjscreate-react-app

create-react-app generates function instead of class in App.js


I'm trying to create react app using create-react-app command, and it's generating the App.js file as function (es5 syntax without class) instead of class (Example in the following code):

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

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;

How can I force create-react-app to generate class instead?


Solution

  • This is the default file when you generate a new project.

    Here's the link to the file that's copied over. I believe the older versions of CRA did have classes, but in terms of forcing it to generate files with classes it's currently not set up to do that.