I've read from the sources that If I update the state of any component than the whole virtual dom will be render ? Is It True ? If Yes, Then Why render method of all component not called ?
Also, Need some clarification on below point -
I assuming that If we compare the virtual dom with actual dom, Virtual dom takes little time to update the dom than real dom. But how can practically prove that ?
How react uses diffing algorithm to update only respective component In which changes happen (If I used setState method)
Any video lecture for that would be really appreciated.
No, what you've read is incorrect.
When you update the state of a component, meaning you have changed part of the virtual DOM, You'd be changing ONLY that specific part of React's virtual DOM and nothing else.
All other components do not get re-rendered whatsoever.
An answer to your questions:
Virtual DOM is a representation of the actual DOM in plain JavaScript object. Comprehensive details on what is virtual DOM can be found in this stackoverflow question and this medium article
Manipulating the real DOM is indeed very expensive in regards to efficiency. On the other side, virtual DOM is very efficient. Here are a couple of articles which can help you understand how: Codecademy and Medium article
Codecademy explains how diffing algorithm works but you can also read the following for further information about mentioned algorithm on React's official documentation.
I believe the articles I found and listed here are sufficient to understand the virtual DOM, the performance difference between virtual DOM and real DOM and how does the diffing algorithm works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With