forlooptanzania / ride-my-way

Car pooling app (of developers) by developers for developers in Tanzania
22 stars 6 forks source link

What is the Virtual DOM? #5

Open chrisoemma opened 5 years ago

chrisoemma commented 5 years ago

I know about the DOM i.e. Document Object Model.

Really, the DOM helps to represent all elements in a web page, in a tree manner. This way, we can easily visualize how to access them programmatically.

Now, I hear React uses the Virtual DOM. Why is it Virtual? Why do we need it?

I am confused. :cry:

BenMaruchu commented 5 years ago

@chrisoemma you can start here https://programmingwithmosh.com/react/react-virtual-dom-explained/

karimkawambwa commented 5 years ago

@chrisoemma

Think of it like doing your own accounts and banking. The DOM is a bank and the Virtual DOM is a bank too except its your wallet.

It is expensive to keep going to the Bank to withraw money, do the accounting etc. So you have your wallet, faster in all ways and do your accounting, pay someone out of your pockets etc.

Whatever is left in your wallet Bank (Virtual DOM) after updating it all day, you make a trip to the Bank (DOM) and make your deposit or withdrawals (changes). This is less expensive (bypassing all those small transaction fees or frequent trips) and faster too.

😁