SlideShare a Scribd company logo
React DOM/Virtual DOM
There are hundreds of articles floating which deal with the comparison of DOM and
React-DOM.But what is React-DOM or what is DOM for that matter.Let’s unwind this.
Advantages of React
React, often stylized as React-dom, has taken the world of web development by storm.
Recognizing the advantages of React and how it interacts with the Document Object Model
(DOM) – a topic that often prompts the question, “what is DOM in React?” – is essential for
both aspiring and seasoned developers. From the component-based approach and React
DOM methods to the virtual DOM concept, React brings several benefits to the table.
Optimized Performance with Virtual DOM
One of the foremost advantages of React is the implementation of the virtual DOM. React
DOM’s ability to minimize direct manipulation of the actual DOM – an operation that’s
computationally expensive and can slow down your app – sets it apart from many other
JavaScript libraries and frameworks.
React’s virtual DOM works by creating a replica of the actual DOM, allowing React to
calculate the most efficient way to make changes. This involves using React DOM methods
for ‘diffing’ (comparing the old and new DOM), and ‘reconciliation’ (updating the actual
DOM to match the new virtual DOM). The overall result? Faster, more efficient applications
that provide a smoother user experience.
Component-Based Architecture
Another crucial advantage of React is its component-based architecture. This approach
allows developers to build applications using reusable components, fostering code
maintainability and reusability. Each component in React has its own state and logic, which
makes it self-contained and helps in isolating bugs and making testing easier.
Even while managing these components, React avoids direct DOM manipulation. In case
you need to access the DOM directly, React provides escape hatches such as the
Reactdom.finddomnode method, although it’s generally discouraged.
Seamless Integration and Backward Compatibility
React’s design allows it to be gradually adopted, meaning you can implement it in small
parts of your project without needing to overhaul the entire codebase. This makes React a
flexible solution that can be introduced into existing projects, making the transition
smoother and less disruptive.
Also, React strives to be backward-compatible. This means that updates to the library aim
not to break your existing code. You can keep your React projects updated with the latest
features and improvements without worrying about significant refactorings.
Server-Side Rendering with Reactdom.hydrate
React also supports server-side rendering (SSR), which can improve the initial load
performance of your application and make it more SEO-friendly. SSR works by rendering
React components on the server and sending the HTML to the browser. The
Reactdom.hydrate function is used to make the server-rendered markup interactive,
ensuring a seamless user experience.
Rich Ecosystem and Community Support
The popularity of React has led to a rich ecosystem of libraries, tools, and resources. From
state management libraries like Redux and MobX, to routing solutions like React-router,
there’s a package for almost every need. Moreover, you’re joining a vibrant community of
developers when you start working with React. This means a wealth of tutorials, guides,
and third-party tools are at your disposal.
Important Points to Remember While Working with React
React, a powerful JavaScript library created by Facebook, has become a vital tool for
building interactive web applications. As you embark on your React development journey,
there are several key points to remember. Notably, understanding React DOM,
Reactdom.finddomnode, and Reactdom.hydrate, along with other important React DOM
methods, is critical to your success.
Component-Based Approach
At the heart of any React application lies a component-based approach. This means that a
React app is built using numerous individual pieces, or components, each responsible for a
distinct part of the user interface. This modular approach has several advantages:
● It promotes code reuse, as components can be used in multiple places throughout
an application.
● It makes code more manageable and easy to test, as each component has its own
logic and controls its own rendering.
● It simplifies the debugging process, as developers can isolate issues to specific
components.
While working with components, you’ll often encounter React DOM manipulation. It’s
important to note that the direct manipulation of the DOM is generally avoided in React.
Instead, the state of components is updated, leading to a change in the virtual DOM, and
eventually, an efficient update of the actual DOM.
Furthermore, React provides several methods to help manipulate the DOM when
necessary. Reactdom.finddomnode is one such method, allowing you to directly access a
DOM node. However, it’s considered an escape hatch and its use is discouraged in most
cases.
Declarative Views in React
Another essential point to remember while working with React is its declarative nature.
When you write a React component, you don’t tell the program how to update the view
when your data changes. Instead, you describe what the view should look like.
React, with the help of its virtual DOM, efficiently updates and renders the appropriate
components when your data changes. The process involves diffing (comparing the new
virtual DOM with the previous one) and reconciliation (updating the real DOM to match the
virtual DOM).
Reactdom.hydrate comes into play when you’re dealing with server-rendered applications.
It enables the client-side React to recognize and preserve the server-rendered markup,
making the app interactive.
What is DOM in React?
DOM is short form of Document Object Model and is actually is just a Javascript object
which is logical representation of any web page.This Javascript object or DOM is structured
in the form of tree and this tree contains all the elements and its properties.And this
elements are treated as nodes.
Whenever during development there is any change in any of the elements the DOM is
required to be updated which implies that the browser has to calculate and load all the
nodes.And then load all the css file, technically speaking repaint the whole web page as per
the CSS. This makes the reload of the web page very slow and so we say the
DOM-manipulation used to be costly before react-dom.
How Virtual DOM Works in React?
React’s power and efficiency come from its unique approach to handling updates in a web
application. A cornerstone of this approach is the usage of a virtual DOM. Let’s break down
how the virtual DOM works:
● Initial Render
When a React application is first loaded, React DOM creates a lightweight copy of the actual
DOM, a process known as the creation of a “virtual DOM”. This is not the visible webpage
but a representation of it in memory.
● Component Updates
As users interact with the application or data changes, your components may update.
These updates could be state changes or prop updates. When an update occurs, React
creates a new virtual DOM to reflect these changes.
● Diffing
React then compares this new virtual DOM (with the updates) to the previous virtual DOM.
This process is known as “diffing”. React identifies which objects have changed in the virtual
DOM through this process.
● Reconciliation
The final step is “reconciliation”. Here, React uses the results from the diffing process to
efficiently update the actual DOM. It only updates the parts of the real DOM that have
changed in the virtual DOM, not the entire page. This leads to significant performance
improvements, as manipulating the real DOM is a costly operation.
● Reactdom.finddomnode
It’s worth noting that Reactdom.finddomnode is a method in React DOM that allows direct
access to a DOM node. It’s often used when you need to interact with the actual DOM,
rather than the virtual one.
● Reactdom.hydrate
Another important method is Reactdom.hydrate, which is used to “hydrate” a container
whose HTML contents were rendered by ReactDOMServer. Hydrating, in this context,
means attaching event listeners to the server-rendered markup functional, interactive
application.
● Optimization
This entire process of dealing with the virtual DOM makes React highly optimized. Since the
real DOM manipulations, which are expensive operations, are minimized, the application
becomes highly efficient and much faster.
● Batched Updates
Another benefit of this process is that React batches multiple updates together to avoid
unnecessary re-renders. This further boosts the application’s performance.
So how does react-dom solve this problem???
React-DOM provides a specific bundle of packages to DOM that can be applied only to the
top level of the app instead of all the components. React DOM comes with some methods.
We will discuss these methods later but it is important to mention here that react-dom or
virtual dom is nothing but a copy of the original javascript dom object.
So whenever there is any manipulation in any of the element the virtual DOM updates
itself(here updating the virtual dom comparatively much cheaper) and only the differences
between the virtual dom and real dom gets updated in real dom(For example if the
element already rendered in the real dom then only changes after comparison between
real dom and virtual dom will be re-rendered and the whole element).
So here there is no direct manipulation in the real dom and which implies faster load of
web page.
Now let’s have a deep dive into react-dom and the methods provided by it such as
render() : This method renders the react element to the given container in the dom and
returns a reference of container or else null if its a stateless container and if there are any
callbacks functions passed to it then executes them only once the component is
rendered.The syntax for the same is as follows
ReactDOM.render(element, container[, callback])
hydrate() : Hydrate works same as render method and follows the same syntax as follows
ReactDOM.hydrate(element, container[, callback])
But it is used to hydrate the container whose html markups are rendered by the
reactDomServer.When I say hydrate the container by that what I mean is react try to
compare the content rendered at the client is whether the same as the server or not. React
generally ignore the mismatches in the text content but it doesn’t work the same way in
case of mismatches with the attributes.
If you have some content which is rendered differently at server and client then you can
suppress the warning by using suppressHydrationWarning .But always guided to keep in
mind to avoid using this as it might lead to some unexpected bug.
unmountComponentAtNode() : As the name of this method is self explanatory.It
unmounts the component and it cleans its event handler from the DOM. The syntax for the
same is as follows
ReactDOM.unmountComponentAtNode(container)
Also this method returns false if there is no component to unmount and returns true it has
successfully unmounts the component.
findDOMNode() : This method is an escape hatch as it will let you access the underlying
DOM node.But ideally it is preferable as it pierces the component abstraction.You can not
use this method in strict mode as it has been deprecated.The syntax to use the same is as
follows :
ReactDOM.findDOMNode(component)
If this component is mounted into the DOM , it returns native browser DOM element and it
the component is rendered to null or false then findDOMNode(component) returns null
else in case of findDOMNode is rendered to string then the component will return text
dom containing thar value.
Also findDOMNode only works in case of the component that has been already rendered.If
you try to use this on the component that does not exist on dom or still has to be rendered
(for example the components in render method) then findDOMNOde will throw an
exception.

More Related Content

Similar to React DOM/Virtual DOM

Top most React js tools to optimize web app
Top most React js tools to optimize web appTop most React js tools to optimize web app
Top most React js tools to optimize web app
Orange Mantra
 
React js vs react native a comparative analysis
React js vs react native a comparative analysisReact js vs react native a comparative analysis
React js vs react native a comparative analysis
Shelly Megan
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
IRJET Journal
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
Ritesh Mehrotra
 
Why do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdfWhy do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdf
nearlearn
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
Ali Sa'o
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
Ritesh Kumar
 
JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
Jordan Open Source Association
 
What is ReactJS?
What is ReactJS?What is ReactJS?
What is ReactJS?
Albiorix Technology
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
SHAIKIRFAN715544
 
Reactjs A javascript Library
Reactjs A javascript LibraryReactjs A javascript Library
Reactjs A javascript Library
Mohit Jain
 
Why Hire React.js Developer for your Upcoming Web App Development Projects?
Why Hire React.js Developer for your Upcoming Web App Development Projects?Why Hire React.js Developer for your Upcoming Web App Development Projects?
Why Hire React.js Developer for your Upcoming Web App Development Projects?
Windzoon Technologies
 
Vue Js vs React: Which is the Best JS Technology in 2023
Vue Js vs React: Which is the Best JS Technology in 2023Vue Js vs React: Which is the Best JS Technology in 2023
Vue Js vs React: Which is the Best JS Technology in 2023
Aman Mishra
 
React js Rahil Memon
React js Rahil MemonReact js Rahil Memon
React js Rahil Memon
RahilMemon5
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
Divyang Bhambhani
 
Nodejs vs react js converted
Nodejs vs react js convertedNodejs vs react js converted
Nodejs vs react js converted
Sovereign software solution
 
React js
React jsReact js
React js
Nikhil Karkra
 
learning react
learning reactlearning react
learning react
Eueung Mulyana
 
How Can the Hermes Engine Help React Native Apps.docx.pdf
How Can the Hermes Engine Help React Native Apps.docx.pdfHow Can the Hermes Engine Help React Native Apps.docx.pdf
How Can the Hermes Engine Help React Native Apps.docx.pdf
Techugo
 
Vue Or React - Which One is the Best_.pptx
Vue Or React - Which One is the Best_.pptxVue Or React - Which One is the Best_.pptx
Vue Or React - Which One is the Best_.pptx
75waytechnologies
 

Similar to React DOM/Virtual DOM (20)

Top most React js tools to optimize web app
Top most React js tools to optimize web appTop most React js tools to optimize web app
Top most React js tools to optimize web app
 
React js vs react native a comparative analysis
React js vs react native a comparative analysisReact js vs react native a comparative analysis
React js vs react native a comparative analysis
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
Why do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdfWhy do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdf
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
 
JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
 
What is ReactJS?
What is ReactJS?What is ReactJS?
What is ReactJS?
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 
Reactjs A javascript Library
Reactjs A javascript LibraryReactjs A javascript Library
Reactjs A javascript Library
 
Why Hire React.js Developer for your Upcoming Web App Development Projects?
Why Hire React.js Developer for your Upcoming Web App Development Projects?Why Hire React.js Developer for your Upcoming Web App Development Projects?
Why Hire React.js Developer for your Upcoming Web App Development Projects?
 
Vue Js vs React: Which is the Best JS Technology in 2023
Vue Js vs React: Which is the Best JS Technology in 2023Vue Js vs React: Which is the Best JS Technology in 2023
Vue Js vs React: Which is the Best JS Technology in 2023
 
React js Rahil Memon
React js Rahil MemonReact js Rahil Memon
React js Rahil Memon
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
Nodejs vs react js converted
Nodejs vs react js convertedNodejs vs react js converted
Nodejs vs react js converted
 
React js
React jsReact js
React js
 
learning react
learning reactlearning react
learning react
 
How Can the Hermes Engine Help React Native Apps.docx.pdf
How Can the Hermes Engine Help React Native Apps.docx.pdfHow Can the Hermes Engine Help React Native Apps.docx.pdf
How Can the Hermes Engine Help React Native Apps.docx.pdf
 
Vue Or React - Which One is the Best_.pptx
Vue Or React - Which One is the Best_.pptxVue Or React - Which One is the Best_.pptx
Vue Or React - Which One is the Best_.pptx
 

More from RajasreePothula3

React ChartJS
React ChartJSReact ChartJS
React ChartJS
RajasreePothula3
 
Best Practices for Building Scalable and Performant React Applications
Best Practices for Building Scalable and Performant React Applications Best Practices for Building Scalable and Performant React Applications
Best Practices for Building Scalable and Performant React Applications
RajasreePothula3
 
We’re Hiring React Native Developer
We’re Hiring React Native Developer We’re Hiring React Native Developer
We’re Hiring React Native Developer
RajasreePothula3
 
How to find the Best React Development Company for your App?
How to find the Best React Development Company for your App? How to find the Best React Development Company for your App?
How to find the Best React Development Company for your App?
RajasreePothula3
 
React Component
React ComponentReact Component
React Component
RajasreePothula3
 
React Architecture
React ArchitectureReact Architecture
React Architecture
RajasreePothula3
 
Guide to Outsourcing ReactJS Development Successfully
Guide to Outsourcing ReactJS Development Successfully Guide to Outsourcing ReactJS Development Successfully
Guide to Outsourcing ReactJS Development Successfully
RajasreePothula3
 
React Error Boundaries
React Error BoundariesReact Error Boundaries
React Error Boundaries
RajasreePothula3
 
Guide to Create React Native App for Android & iOS Platforms
Guide to Create React Native App for Android & iOS Platforms Guide to Create React Native App for Android & iOS Platforms
Guide to Create React Native App for Android & iOS Platforms
RajasreePothula3
 
What are package managers?
What are package managers? What are package managers?
What are package managers?
RajasreePothula3
 
React Development Services
React Development ServicesReact Development Services
React Development Services
RajasreePothula3
 
Learn Stateful and Stateless components in ReactJS
Learn Stateful and Stateless components in ReactJS Learn Stateful and Stateless components in ReactJS
Learn Stateful and Stateless components in ReactJS
RajasreePothula3
 
Building and Deploying Serverless Applications with NextJS and Vercel.pdf
Building and Deploying Serverless Applications with NextJS and Vercel.pdfBuilding and Deploying Serverless Applications with NextJS and Vercel.pdf
Building and Deploying Serverless Applications with NextJS and Vercel.pdf
RajasreePothula3
 

More from RajasreePothula3 (13)

React ChartJS
React ChartJSReact ChartJS
React ChartJS
 
Best Practices for Building Scalable and Performant React Applications
Best Practices for Building Scalable and Performant React Applications Best Practices for Building Scalable and Performant React Applications
Best Practices for Building Scalable and Performant React Applications
 
We’re Hiring React Native Developer
We’re Hiring React Native Developer We’re Hiring React Native Developer
We’re Hiring React Native Developer
 
How to find the Best React Development Company for your App?
How to find the Best React Development Company for your App? How to find the Best React Development Company for your App?
How to find the Best React Development Company for your App?
 
React Component
React ComponentReact Component
React Component
 
React Architecture
React ArchitectureReact Architecture
React Architecture
 
Guide to Outsourcing ReactJS Development Successfully
Guide to Outsourcing ReactJS Development Successfully Guide to Outsourcing ReactJS Development Successfully
Guide to Outsourcing ReactJS Development Successfully
 
React Error Boundaries
React Error BoundariesReact Error Boundaries
React Error Boundaries
 
Guide to Create React Native App for Android & iOS Platforms
Guide to Create React Native App for Android & iOS Platforms Guide to Create React Native App for Android & iOS Platforms
Guide to Create React Native App for Android & iOS Platforms
 
What are package managers?
What are package managers? What are package managers?
What are package managers?
 
React Development Services
React Development ServicesReact Development Services
React Development Services
 
Learn Stateful and Stateless components in ReactJS
Learn Stateful and Stateless components in ReactJS Learn Stateful and Stateless components in ReactJS
Learn Stateful and Stateless components in ReactJS
 
Building and Deploying Serverless Applications with NextJS and Vercel.pdf
Building and Deploying Serverless Applications with NextJS and Vercel.pdfBuilding and Deploying Serverless Applications with NextJS and Vercel.pdf
Building and Deploying Serverless Applications with NextJS and Vercel.pdf
 

Recently uploaded

Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta MatkaDpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta Matka
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...
❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...
❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...
❼❷⓿❺❻❷❽❷❼❽ Dpboss Kalyan Satta Matka Guessing Matka Result Main Bazar chart
 
The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...
The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...
The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...
Stephen Cashman
 
The latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from NewentideThe latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from Newentide
JoeYangGreatMachiner
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
techboxsqauremedia
 
Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...
Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...
Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...
my Pandit
 
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your TasteZodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
my Pandit
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
LuanWise
 
Understanding User Needs and Satisfying Them
Understanding User Needs and Satisfying ThemUnderstanding User Needs and Satisfying Them
Understanding User Needs and Satisfying Them
Aggregage
 
Income Tax exemption for Start up : Section 80 IAC
Income Tax  exemption for Start up : Section 80 IACIncome Tax  exemption for Start up : Section 80 IAC
Income Tax exemption for Start up : Section 80 IAC
CA Dr. Prithvi Ranjan Parhi
 
Call8328958814 satta matka Kalyan result satta guessing
Call8328958814 satta matka Kalyan result satta guessingCall8328958814 satta matka Kalyan result satta guessing
Call8328958814 satta matka Kalyan result satta guessing
➑➌➋➑➒➎➑➑➊➍
 
2024-6-01-IMPACTSilver-Corp-Presentation.pdf
2024-6-01-IMPACTSilver-Corp-Presentation.pdf2024-6-01-IMPACTSilver-Corp-Presentation.pdf
2024-6-01-IMPACTSilver-Corp-Presentation.pdf
hartfordclub1
 
3 Simple Steps To Buy Verified Payoneer Account In 2024
3 Simple Steps To Buy Verified Payoneer Account In 20243 Simple Steps To Buy Verified Payoneer Account In 2024
3 Simple Steps To Buy Verified Payoneer Account In 2024
SEOSMMEARTH
 
Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024
Top Forex Brokers Review
 
How MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdfHow MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdf
MJ Global
 
Part 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 SlowdownPart 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 Slowdown
jeffkluth1
 
Digital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on SustainabilityDigital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on Sustainability
sssourabhsharma
 
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel ChartSatta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
Best practices for project execution and delivery
Best practices for project execution and deliveryBest practices for project execution and delivery
Best practices for project execution and delivery
CLIVE MINCHIN
 
Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)
Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)
Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)
Lviv Startup Club
 

Recently uploaded (20)

Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta MatkaDpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Satta Matka
 
❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...
❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...
❼❷⓿❺❻❷❽❷❼❽ Dpboss Matka Result Satta Matka Guessing Satta Fix jodi Kalyan Fin...
 
The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...
The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...
The Heart of Leadership_ How Emotional Intelligence Drives Business Success B...
 
The latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from NewentideThe latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from Newentide
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
 
Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...
Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...
Unveiling the Dynamic Personalities, Key Dates, and Horoscope Insights: Gemin...
 
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your TasteZodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
 
Understanding User Needs and Satisfying Them
Understanding User Needs and Satisfying ThemUnderstanding User Needs and Satisfying Them
Understanding User Needs and Satisfying Them
 
Income Tax exemption for Start up : Section 80 IAC
Income Tax  exemption for Start up : Section 80 IACIncome Tax  exemption for Start up : Section 80 IAC
Income Tax exemption for Start up : Section 80 IAC
 
Call8328958814 satta matka Kalyan result satta guessing
Call8328958814 satta matka Kalyan result satta guessingCall8328958814 satta matka Kalyan result satta guessing
Call8328958814 satta matka Kalyan result satta guessing
 
2024-6-01-IMPACTSilver-Corp-Presentation.pdf
2024-6-01-IMPACTSilver-Corp-Presentation.pdf2024-6-01-IMPACTSilver-Corp-Presentation.pdf
2024-6-01-IMPACTSilver-Corp-Presentation.pdf
 
3 Simple Steps To Buy Verified Payoneer Account In 2024
3 Simple Steps To Buy Verified Payoneer Account In 20243 Simple Steps To Buy Verified Payoneer Account In 2024
3 Simple Steps To Buy Verified Payoneer Account In 2024
 
Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024
 
How MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdfHow MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdf
 
Part 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 SlowdownPart 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 Slowdown
 
Digital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on SustainabilityDigital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on Sustainability
 
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel ChartSatta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
 
Best practices for project execution and delivery
Best practices for project execution and deliveryBest practices for project execution and delivery
Best practices for project execution and delivery
 
Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)
Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)
Maksym Vyshnivetskyi: PMO KPIs (UA) (#12)
 

React DOM/Virtual DOM

  • 1. React DOM/Virtual DOM There are hundreds of articles floating which deal with the comparison of DOM and React-DOM.But what is React-DOM or what is DOM for that matter.Let’s unwind this. Advantages of React React, often stylized as React-dom, has taken the world of web development by storm. Recognizing the advantages of React and how it interacts with the Document Object Model (DOM) – a topic that often prompts the question, “what is DOM in React?” – is essential for both aspiring and seasoned developers. From the component-based approach and React DOM methods to the virtual DOM concept, React brings several benefits to the table. Optimized Performance with Virtual DOM One of the foremost advantages of React is the implementation of the virtual DOM. React DOM’s ability to minimize direct manipulation of the actual DOM – an operation that’s computationally expensive and can slow down your app – sets it apart from many other JavaScript libraries and frameworks. React’s virtual DOM works by creating a replica of the actual DOM, allowing React to calculate the most efficient way to make changes. This involves using React DOM methods for ‘diffing’ (comparing the old and new DOM), and ‘reconciliation’ (updating the actual DOM to match the new virtual DOM). The overall result? Faster, more efficient applications that provide a smoother user experience. Component-Based Architecture Another crucial advantage of React is its component-based architecture. This approach allows developers to build applications using reusable components, fostering code
  • 2. maintainability and reusability. Each component in React has its own state and logic, which makes it self-contained and helps in isolating bugs and making testing easier. Even while managing these components, React avoids direct DOM manipulation. In case you need to access the DOM directly, React provides escape hatches such as the Reactdom.finddomnode method, although it’s generally discouraged. Seamless Integration and Backward Compatibility React’s design allows it to be gradually adopted, meaning you can implement it in small parts of your project without needing to overhaul the entire codebase. This makes React a flexible solution that can be introduced into existing projects, making the transition smoother and less disruptive. Also, React strives to be backward-compatible. This means that updates to the library aim not to break your existing code. You can keep your React projects updated with the latest features and improvements without worrying about significant refactorings. Server-Side Rendering with Reactdom.hydrate React also supports server-side rendering (SSR), which can improve the initial load performance of your application and make it more SEO-friendly. SSR works by rendering React components on the server and sending the HTML to the browser. The Reactdom.hydrate function is used to make the server-rendered markup interactive, ensuring a seamless user experience. Rich Ecosystem and Community Support The popularity of React has led to a rich ecosystem of libraries, tools, and resources. From state management libraries like Redux and MobX, to routing solutions like React-router, there’s a package for almost every need. Moreover, you’re joining a vibrant community of developers when you start working with React. This means a wealth of tutorials, guides, and third-party tools are at your disposal. Important Points to Remember While Working with React
  • 3. React, a powerful JavaScript library created by Facebook, has become a vital tool for building interactive web applications. As you embark on your React development journey, there are several key points to remember. Notably, understanding React DOM, Reactdom.finddomnode, and Reactdom.hydrate, along with other important React DOM methods, is critical to your success. Component-Based Approach At the heart of any React application lies a component-based approach. This means that a React app is built using numerous individual pieces, or components, each responsible for a distinct part of the user interface. This modular approach has several advantages: ● It promotes code reuse, as components can be used in multiple places throughout an application. ● It makes code more manageable and easy to test, as each component has its own logic and controls its own rendering. ● It simplifies the debugging process, as developers can isolate issues to specific components. While working with components, you’ll often encounter React DOM manipulation. It’s important to note that the direct manipulation of the DOM is generally avoided in React. Instead, the state of components is updated, leading to a change in the virtual DOM, and eventually, an efficient update of the actual DOM. Furthermore, React provides several methods to help manipulate the DOM when necessary. Reactdom.finddomnode is one such method, allowing you to directly access a DOM node. However, it’s considered an escape hatch and its use is discouraged in most cases. Declarative Views in React Another essential point to remember while working with React is its declarative nature. When you write a React component, you don’t tell the program how to update the view when your data changes. Instead, you describe what the view should look like.
  • 4. React, with the help of its virtual DOM, efficiently updates and renders the appropriate components when your data changes. The process involves diffing (comparing the new virtual DOM with the previous one) and reconciliation (updating the real DOM to match the virtual DOM). Reactdom.hydrate comes into play when you’re dealing with server-rendered applications. It enables the client-side React to recognize and preserve the server-rendered markup, making the app interactive. What is DOM in React? DOM is short form of Document Object Model and is actually is just a Javascript object which is logical representation of any web page.This Javascript object or DOM is structured in the form of tree and this tree contains all the elements and its properties.And this elements are treated as nodes. Whenever during development there is any change in any of the elements the DOM is required to be updated which implies that the browser has to calculate and load all the nodes.And then load all the css file, technically speaking repaint the whole web page as per the CSS. This makes the reload of the web page very slow and so we say the DOM-manipulation used to be costly before react-dom. How Virtual DOM Works in React? React’s power and efficiency come from its unique approach to handling updates in a web application. A cornerstone of this approach is the usage of a virtual DOM. Let’s break down how the virtual DOM works: ● Initial Render
  • 5. When a React application is first loaded, React DOM creates a lightweight copy of the actual DOM, a process known as the creation of a “virtual DOM”. This is not the visible webpage but a representation of it in memory. ● Component Updates As users interact with the application or data changes, your components may update. These updates could be state changes or prop updates. When an update occurs, React creates a new virtual DOM to reflect these changes. ● Diffing React then compares this new virtual DOM (with the updates) to the previous virtual DOM. This process is known as “diffing”. React identifies which objects have changed in the virtual DOM through this process. ● Reconciliation The final step is “reconciliation”. Here, React uses the results from the diffing process to efficiently update the actual DOM. It only updates the parts of the real DOM that have changed in the virtual DOM, not the entire page. This leads to significant performance improvements, as manipulating the real DOM is a costly operation. ● Reactdom.finddomnode It’s worth noting that Reactdom.finddomnode is a method in React DOM that allows direct access to a DOM node. It’s often used when you need to interact with the actual DOM, rather than the virtual one. ● Reactdom.hydrate Another important method is Reactdom.hydrate, which is used to “hydrate” a container whose HTML contents were rendered by ReactDOMServer. Hydrating, in this context, means attaching event listeners to the server-rendered markup functional, interactive application. ● Optimization
  • 6. This entire process of dealing with the virtual DOM makes React highly optimized. Since the real DOM manipulations, which are expensive operations, are minimized, the application becomes highly efficient and much faster. ● Batched Updates Another benefit of this process is that React batches multiple updates together to avoid unnecessary re-renders. This further boosts the application’s performance. So how does react-dom solve this problem??? React-DOM provides a specific bundle of packages to DOM that can be applied only to the top level of the app instead of all the components. React DOM comes with some methods. We will discuss these methods later but it is important to mention here that react-dom or virtual dom is nothing but a copy of the original javascript dom object. So whenever there is any manipulation in any of the element the virtual DOM updates itself(here updating the virtual dom comparatively much cheaper) and only the differences between the virtual dom and real dom gets updated in real dom(For example if the element already rendered in the real dom then only changes after comparison between real dom and virtual dom will be re-rendered and the whole element). So here there is no direct manipulation in the real dom and which implies faster load of web page. Now let’s have a deep dive into react-dom and the methods provided by it such as render() : This method renders the react element to the given container in the dom and returns a reference of container or else null if its a stateless container and if there are any
  • 7. callbacks functions passed to it then executes them only once the component is rendered.The syntax for the same is as follows ReactDOM.render(element, container[, callback]) hydrate() : Hydrate works same as render method and follows the same syntax as follows ReactDOM.hydrate(element, container[, callback]) But it is used to hydrate the container whose html markups are rendered by the reactDomServer.When I say hydrate the container by that what I mean is react try to compare the content rendered at the client is whether the same as the server or not. React generally ignore the mismatches in the text content but it doesn’t work the same way in case of mismatches with the attributes. If you have some content which is rendered differently at server and client then you can suppress the warning by using suppressHydrationWarning .But always guided to keep in mind to avoid using this as it might lead to some unexpected bug. unmountComponentAtNode() : As the name of this method is self explanatory.It unmounts the component and it cleans its event handler from the DOM. The syntax for the same is as follows ReactDOM.unmountComponentAtNode(container) Also this method returns false if there is no component to unmount and returns true it has successfully unmounts the component. findDOMNode() : This method is an escape hatch as it will let you access the underlying DOM node.But ideally it is preferable as it pierces the component abstraction.You can not use this method in strict mode as it has been deprecated.The syntax to use the same is as follows : ReactDOM.findDOMNode(component)
  • 8. If this component is mounted into the DOM , it returns native browser DOM element and it the component is rendered to null or false then findDOMNode(component) returns null else in case of findDOMNode is rendered to string then the component will return text dom containing thar value. Also findDOMNode only works in case of the component that has been already rendered.If you try to use this on the component that does not exist on dom or still has to be rendered (for example the components in render method) then findDOMNOde will throw an exception.