What else does the React.Component class provide?

Question

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

Answer

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.

14 Likes