Saturday, June 6, 2020

React Render HTML

React renders HTML to the web page by using a function called ReactDOM.render(). The ReactDOM.render() function takes two arguments,

HTML code and an HTML element.

The purpose of the function is to display the specified HTML code inside the specified HTML element. 


Display a paragraph inside the "root" element:

ReactDOM.render(<p>Hello</p>, document.getElementById('root'));

The result is displayed in the <div id="root"> element:

<body>

  <div id="root"></div>

</body>

The Root Node

  • The root node is the HTML element where you want to display the result.

  • It is like a container for content managed by React.

  • It does NOT have to be a <div> element and it does NOT have to have the id='root'

No comments:

Post a Comment