The Wayback Machine - https://web.archive.org/web/20240808004111/https://www.geeksforgeeks.org/reactjs-reactdom/
Open In App

React JS ReactDOM

Last Updated : 24 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

React JS ReactDOM or react-dom is the most widely used package of React. React provides the developers with a package react-dom to access and modify the DOM. Let’s see in brief what is the need to have the package. 

What is ReactDOM ? 

ReactDOM is a package in React that provides DOM-specific methods that can be used at the top level of a web app to enable an efficient way of managing DOM elements of the web page. ReactDOM provides the developers with an API containing the various methods to manipulate DOM. 

How to use ReactDOM ?

To use the ReactDOM in any React web app we must first install the react-dom package in our project. To install the react-dom package use the following command.

// Installing
npm i react-dom

After installing the package use the following command to import the package in your application file

// Importing
import ReactDOM from 'react-dom'

After installing react-dom it will appear in the dependenices in package.json file like:

"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
}

Why ReactDOM is used ?

Earlier, React Developers directly manipulated the DOM elements which resulted in frequent DOM manipulation, and each time an update was made the browser had to recalculate and repaint the whole view according to the particular CSS of the page, which made the total process to consume a lot of time.

To solve this issue, React brought into the scene the virtual DOM. The Virtual DOM can be referred to as a copy of the actual DOM representation that is used to hold the updates made by the user and finally reflect it over to the original Browser DOM at once consuming much lesser time. 

Important functions provided by ReactDOM

  • render(): This is one of the most important methods of ReactDOM. This function is used to render a single React Component or several Components wrapped together in a Component or a div element. 
  • findDOMNode(): This function is generally used to get the DOM node where a particular React component was rendered. This method is very less used like the following can be done by adding a ref attribute to each component itself.
  • unmountComponentAtNode(): This function is used to unmount or remove the React Component that was rendered to a particular container.
  • hydrate(): This method is equivalent to the render() method but is implemented while using server-side rendering. 
  • createPortal(): It allow us to render a component into a DOM node that resides outside the current DOM hierarchy of the parent component. 

Key features of ReactDOM :

  • ReactDOM.render() replaces the child of the given container if any. It uses a highly efficient diff algorithm and can modify any subtree of the DOM.
  • React findDOMNode() function can only be implemented upon mounted components thus Functional components can not be used in findDOMNode() method.
  • ReactDOM uses observables thus provides an efficient way of DOM handling.
  • ReactDOM can be used on both the client-side and server-side.

Previous Article
Next Article

Similar Reads

How React and ReactDOM works?
When you work with React, it is more than likely that you will build your apps with JSX. The JSX is a tag-based JavaScript syntax like looks familiar with HTML. React element is the atomic and most basic unit that you need to master before JSX and before moving forward with React. Note: In order to work with React in the browsers, we need to includ
9 min read
Create a Card View in React native using react-native-paper
React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UIs for both platforms. Approach: In this ar
2 min read
Create an Activity Indicator in react-native using react-native-paper library
React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UIs for both platforms. Prerequisites: Basic
2 min read
React Suite Icon extension React Icons
A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Icon extension React icons. React Icons, contains various popular
3 min read
Implement Nested Routes in React.js - React Router DOM V6
Nested routes in React JS are implemented using the outlet in React Router Dom. Routing in React not only provides routing for the pages but also for switching the content inside that page. Nested routes implement this by defining Routes for Child components inside parent route components. Prerequisites: React JSReact RouterReact Router DomApproach
4 min read
How to Add MUI React Button Icon in React-Bootstrap ?
In this article, we will learn how to add the mui react button icon in react-bootstrap. Icons can be added in the react-bootstrap by importing the MUI icon component and using it within your React-Bootstrap button. React-Bootstrap is a front-end framework that was designed keeping React in mind. Steps to Create React Application And Installing Modu
2 min read
Mastering React Routing: Learn Navigation and Routing in React Apps
In this article, we will learn how to implement Routing in React in an efficient way by implementing various aspects of routing such as dynamic routing, programmatically routing, and other concepts. Table of ContentWhat is Navigation in React?Routing with no page found(error 404) error handlingProgrammatic Navigation in ReactDynamic Routing with Re
6 min read
How to import from React-Select CDN with React and Babel ?
In ReactJS, import from React-Select CDN is not done in a simple way as we do with the npm packages. To use them we need to use directly them in the HTML file. It does not work with the project set-up by creating a react app. Prerequisites:React JSHTML, CSS, JavaScriptSteps to Import React-Select CDN with React and Babel:Step 1: Create index.html w
2 min read
Explain new features of React Memo in React v16.6 ?
React memo is a Higher Order Component (HOC) introduced in React v16.6. As the name suggests, Memo API uses the memoization technique to optimize performance and make the application faster. The Memo API avoids unnecessary re-renders in functional components thereby optimizing the performance of the application. We will see two different examples m
2 min read
What is the difference between react-fetch and whatwg-fetch in React.js ?
React-fetch and Whatwg-fetch are both libraries for making HTTP requests in a React application, but they are used for different purposes and have different features. Table of Content React-fetchWhatwg-fetchDifference between React-fetch and Whatwg-fetchReact-fetch: `react-fetch` is a library offering a higher-order component (HOC) for streamlined
2 min read
three90RightbarBannerImg