Search code examples
javascriptreactjscreate-react-app

How can I configure create-react-app to create an app with classes and not functions?


I am following a YouTube tutorial in order to learn React, but I noticed something annoying. When I create a new app with create-react-app, the app.js is using a function App(), and not a class. I know React can be coded both ways, but I would like to work with classes. Is there any way I can configure create-react-app to create a React app with classes? Something like adding an argument on the CLI, or maybe change an option on a setup page (I couldn't find any).

function App() {}

What I want:

class App extends Component {}

Solution

  • What you are observing is not adjustable by configuration. They changed the App.js generation in create-react-app from class to function with commit e4fdac2 and commit b424737. You are using a version of create-react-app more recent than the videos you are watching. Either syntax is valid, depending on whether you need state or not, but you will have to alter the code yourself to use the former class syntax in App.js.