Rendering
Elements are the smallest building blocks of React apps.
An element describes what you want to see on the screen
Before diving in to see how these are created in React, let’s take a look at how DOM elements are generally created using plain JavaScript:
React.createElement()
React.createElement()
Creating elements in React has many similarities to creating elements in the DOM. We need to specify the type of element we want to create, give it certain parameters (called props in React), and the children that should be rendered within our element.
Notice how the HTML class
attribute has to be set via the className
property in React. This is because class
is a reserved keyword in JavaScript.
Note that React elements are a lightweight representation of the DOM, and are not actual DOM elements. They are represented as plain objects and are cheap to create.
ReactDOM
React is split into two different packages, react
and react-dom
. The react-dom
package provides DOM-specific methods that can be used at the top level of your app to render React elements into DOM elements.
ReactDOM.render()
ReactDOM.render()
The ReactDOM.render()
method is used to render React Elements to the DOM, and takes two arguments:
The ReactElement to render
The DOM node we want to render into (the “entry point”)
Last updated