Skip to content

What Does Rendering Elements Mean in React?

In React, "rendering elements" is the process of drawing React elements on the screen to show them to the user. React elements are lightweight, plain objects that usually describe HTML elements. Since React 18 they are placed in the DOM with the render() method of a root created with createRoot. Here is the process in more detail:

  1. Creating an element: In React everything starts as an element. Elements can describe HTML tags such as div, span or button, or your own components. For example, const element = <h1>Hello, world!</h1>; creates an h1 element.

  2. Rendering the element: To show an element, you first create a root for the target DOM node and then render the element into it. For example: const root = ReactDOM.createRoot(document.getElementById('root')); root.render(element);. This places element in the DOM node whose id is root.

  3. Updates: React elements are immutable; once created, their children and attributes cannot change. To update the UI you create a new element and render it again with root.render(). React compares the previous and the new elements and applies only the DOM updates that are needed.

  4. Virtual DOM: React works out changes on a "virtual DOM" before touching the real DOM. This improves performance, because working with the real DOM is expensive; React finds what changed and updates the real DOM as efficiently as possible.

  5. Component-based approach: React encourages building UIs from independent, reusable components, each managing its own state and rendering on its own.

This is a basic summary of rendering elements in React — the foundation every React application is built on, and what makes dynamic, interactive interfaces easy to build.

Have a question about this article? Write to me