What else does the React.Component class provide?


In the context of this exercise, what else does the React.Component class provide?


The React.Component class provides several methods in addition to render(), some of which are automatically invoked through the lifecycle of the component.

The constructor() method is invoked by the component before it is added to the DOM. This is usually used to run code to set up the component such as initializing some state and binding methods to the component.

The class also provides a componentDidMount() method which is run right after the component is inserted into the DOM tree, and is invoked only one time.

Another method is componentDidUpdate(), which runs immediately after any updates to the component occurs. This is typically used for code such as network requests which should be run if any updates occur to the component.


Is React.Component method a Super Class ? that we extends it with name of MyComponentClass as a child calss ? I can see render() as alternative to constructor method while dealing with supercalss and class why it is named render instead of constructor? , what is this ? I’m confused trying to relate it . why render() takes no arguments and why we didn’t make an object out of class we made with superClass React.component ? how return works here ?


If ‘render’ method is already defined inside the React.Component then why do we have to define it in the class which inherits from it?

I think, it’s not a definition, but a call??

Yeah, at first it looks like a call, but as it turns out, it actually isn’t:

The only method you must define in a React.Component subclass is called render(). All the other methods described on this page are optional.

You like give the render() method a meaning. The only thing that confuses me, is that why is there no function keyword used? Is the function like… declared during creation of the React.Component class and then later we redefine it? Is it possible? I didn’t find any relevant information on that. I am fairly new to programming myself and do not understand everything yet.
I found the answer to my question: the syntax comes from JavaScript basic class syntax:

class MyClass {
  // class methods
  constructor() { ... }
  method1() { ... }
  method2() { ... }
  method3() { ... }

JavaScript Classes](JavaScript Classes)

I guess my JavaScript knowledge needs improving :flushed: