Home > Mobile >  Can a class be a property of an object? Is this what React.Component is?
Can a class be a property of an object? Is this what React.Component is?

Time:12-07

I've been learning about classes and React and came across the React.Component class which you extend to create a class component. I understand that React.Component must be a class if we extend it but then what is the overall React part? is it just an object on which Component is a property as a class, since we access it with dot notation? I've not seen examples of objects where a class can be a property in any of my tutorials. Would love to understand this.

CodePudding user response:

Classes can be referenced and assigned to object property values just like other things.

class Component {}

const React = { Component: Component };

class MyComponent extends React.Component {}
  • Related