Is the ReactDOM render() method the same as the component render() method?

Question

In the context of this exercise, is the ReactDOM render() method the same as the component render() method?

Answer

No, although they have the same name, they are not the same.

The ReactDOM.render() method is used to render a React element into the DOM within the specified container, and returns a reference to that component. It is applied the following way,

ReactDOM.render(
  <MyClass />, 
  document.getElementById('app')
);

On the other hand, the React component render() method returns the elements that make up the component. For instance,

class MyClass extends React.Component {
  render() {
    return <h1>Hello world</h1>;
  }
}
10 Likes