Search code examples
reactjscreate-react-app

Is it best practice to not have App.js extend React.Component?


If I create a new project with create-react-app, I get an App.js module where the default export, App, is just a function, and therefore doesn't have state, which is annoying. Does this suggest that I should have a (root) component under App if I want root level state, or should I just make my App extend React.Component? I don't want to go against convention, and it seems like there's a reason, so thought I would ask.


Solution

  • It is best practice to use Functional component over Class-Component. If that is possible.

    Because create-react-app doesn't know you need state it creates simplest solution for you which you may change. There is nothing wrong with that.