Search code examples
javascriptreactjsconstructorstatelesscomponent-design

ReactJS: What are some criteria for not needing a constructor in a component class?


I want to know the conditions where by a constructor is not needed in a component's class declaration. I figure it is for stateless components, but are there any other reasons? Would not having any functions inside the component (besides life cycle functions) be one, for example?


Solution

  • I think it would be appropriate to just leave here an excerpt from react docs (emphasis mine):

    The constructor is the right place to initialize state. If you don't initialize state and you don't bind methods, you don't need to implement a constructor for your React component.