12 - ReactJS Virtual DOM - What are Virtual DOM, Reconciliation, Diffing, and Batch Update in React?

Sdílet
Vložit
  • čas přidán 2. 08. 2024
  • "What is Virtual DOM in React?" - Have you heard someone asking this question to you? 😉
    So, let's provide the answer to that question. We will also learn the concepts of Reconciliation, Diffing algorithms, and Batch Updates to the original DOM. All set? Let's get started. 🐥
    Timecodes
    0:00 - Introduction
    00:38 - Understanding DOM
    05:30 - ReactJS Virtual DOM
    08:46 - How does Virtual DOM work?
    12:53 - What is Reconciliation Process in React?
    14:02 - What is Diffing Algorithm?
    17:48 - Wrapping Up
    Important Links
    -----------------------------
    - Twitter: / tapasadhikary
    - Blog: blog.greenroots.info/
    - Showwcase React Community: www.showwcase.com/community/r...
    Liked my work? Do you want to support my work?
    * www.buymeacoffee.com/greenroots
    Thank You 🙏

Komentáře • 170

  • @tapasadhikary
    @tapasadhikary  Před 2 lety +5

    Content of the Video
    0:00 - Introduction
    00:38 - Understanding DOM
    05:30 - ReactJS Virtual DOM
    08:46 - How does Virtual DOM work?
    12:53 - What is Reconciliation Process in React?
    14:02 - What is Diffing Algorithm?
    17:48 - Wrapping Up

  • @farazali5335
    @farazali5335 Před rokem +55

    Virtual DOM and Reconciliation:
    React creates a copy of original dom to avoid making direct changes in the original.
    When a change occurs in any state, a new copy of virtual dom is created reflecting that change,
    Now react will do diffing on the new and earlier virtual dom to specify the changes,
    And now it will batchup changes of several virtual doms finally reflect it in the original DOM. This process is called Reconciliation.
    Diffing Algorithm
    1- If the root or parent element has changed, its child elements are considered to be changes as well
    and will be included in the reconciliation.
    2- When checking li elements, the diff algorithm checks all elements to match for any changes or removed or new element.
    This takes a toll on performance and thats why keys are used when printing list items as such, to make the differentiation
    easier and faster.

    • @tapasadhikary
      @tapasadhikary  Před rokem

      Great 👏

    • @mrmadhan8557
      @mrmadhan8557 Před rokem +1

      great summary thank you brother

    • @tapasadhikary
      @tapasadhikary  Před rokem

      Most welcome 🔥

    • @miraclenerdkidchiki6249
      @miraclenerdkidchiki6249 Před rokem +2

      Nice summary bruv 💯

    • @arankengineer7947
      @arankengineer7947 Před 10 měsíci

      sir , above in line 5 , => "And now it will batchup changes of several virtual doms finally reflect it in the original DOM " ,does it mean for any event if state get change it create different virtual dom for parent and every child component ? and what if multiple states of the same component get changed for any event will it create that many virtual dom@@tapasadhikary

  • @martinkarugaba
    @martinkarugaba Před rokem +15

    I have been writing React js code for three years but I had never wrapped my head around the concept of the virtual DOM. Your explanation today was exceptionally clear. Thank you very much Tapas. Please continue doing this. I think you're really good at it.

    • @tapasadhikary
      @tapasadhikary  Před rokem +1

      Thanks, Martin. I am very glad to add to your knowledge. Keep learning, Man!

  • @mumbaikapunter007
    @mumbaikapunter007 Před 2 lety +1

    Thanks mate, short and crisp, to the point. Keep up the good work

  • @rohanthakur9159
    @rohanthakur9159 Před rokem +1

    Thanks a lot Tapas for explaining in such a simple manner. I got to learn a lot from your video. Keep up the good work.👏

  • @mrmadhan8557
    @mrmadhan8557 Před rokem +1

    by far the best explanation i can get on reconciliation. Thanks a lot subbed

  • @deepakkumarkhatri
    @deepakkumarkhatri Před 10 měsíci +1

    Thank you, sir, for contributing to this video. You have explained everything smoothly and I've cleared all my doubts. Keep doing great work for the community.

  • @shashankbhatgs1150
    @shashankbhatgs1150 Před rokem +2

    Wow, just the right video i was looking for.
    Came here to understand just reconciliation, but understood so many concepts like virtual dom, diffing and especially why we use the key attribute. Thanks for making this amazing video!

    • @tapasadhikary
      @tapasadhikary  Před rokem +1

      Yay, so glad to hear that. Feel free to check other videos too from the React series 👏🚀💛

    • @shashankbhatgs1150
      @shashankbhatgs1150 Před rokem

      sure, definitely!

  • @ricklove8358
    @ricklove8358 Před rokem +1

    man this is what i exactly needed. God bless you. Showing love from Tanzania

  • @pratikdevle5830
    @pratikdevle5830 Před 2 lety +1

    short and clear explanation, beginner friendly really liked it.

  • @lindatochukwu3081
    @lindatochukwu3081 Před 7 měsíci +2

    I'm on the 12th video, I never understood some concepts, but going through your videos, boosted my confidence in some concepts in React JS, thank you so much for breaking it down into understandable pieces

  • @sublimeelectrons8699
    @sublimeelectrons8699 Před 10 měsíci

    thank you sir @tapas! Very well explained. Now I understood why react is undoubtedly fast. I understooD DOM, Virtual DOM ,Diffing(Its like Differential signals in signal mixing) algorithm in just 18minutes. Nobody does it better than you sir. Great job again and again.

  • @supershinobi7892
    @supershinobi7892 Před rokem

    i never had any lecture like this love it

  • @ajayarya3914
    @ajayarya3914 Před rokem +1

    Very clean and clear explanation. Awesome 👍

  • @jinoshkurisinkal3169
    @jinoshkurisinkal3169 Před rokem +1

    Crystal clear explanation of Virtual DOM.

  • @talhaahmad7179
    @talhaahmad7179 Před 2 lety +1

    Best video i found on the topic in two days 👍

  • @Sanyat100
    @Sanyat100 Před 10 měsíci +1

    easily the best explanation in the internet about DOM

  • @khemendrabhardwaj8805
    @khemendrabhardwaj8805 Před rokem +1

    Loved the concept .
    Thanks for amazing explanation

  • @kavithakesavan8938
    @kavithakesavan8938 Před měsícem

    so far the best explanation for virtual dom

  • @faizanabbas-i
    @faizanabbas-i Před 4 měsíci +1

    Really Helpful Video to understand these concepts. Thanks for providing such content.

  • @techexpertpremiere
    @techexpertpremiere Před rokem +1

    Thank you for this great explanation of React Virtual DOM. I did not know much about react virtual dom. It seems like to see your video I clear all doubt about the react virtual DOM. Again Thank you.

    • @tapasadhikary
      @tapasadhikary  Před rokem +1

      I am glad that you found it helpful, Omar.

    • @techexpertpremiere
      @techexpertpremiere Před rokem +1

      @@tapasadhikary Your tutorial was the main factor of clear about react virtual dom or VDOM.
      I think every react developer should know about the concept of VDOM. I think this concept will be help me lot in future when I will worked with react project.

    • @tapasadhikary
      @tapasadhikary  Před rokem +1

      Very glad to know 🤩

  • @rishiranjan2822
    @rishiranjan2822 Před 2 lety

    Sir this is absolutely gold explanation....cleared many doubts...tysm!

  • @miraclenerdkidchiki6249
    @miraclenerdkidchiki6249 Před rokem +1

    I love this teaching method....its so in-depth and clearly explained...thanks so much brother👍

  • @cyberdaria
    @cyberdaria Před rokem +1

    Nice and clear vid, thanks!

  • @TheCodingCollege8462
    @TheCodingCollege8462 Před 2 měsíci +1

    Thank you boss

  • @Victor-wh9bs
    @Victor-wh9bs Před rokem +1

    Great explanation.ThankU

  • @shubham5646
    @shubham5646 Před 6 měsíci

    what a teaching style and content u have amazing

  • @harshitrajani8369
    @harshitrajani8369 Před rokem +1

    Great video
    please keep posting

  • @visheshgupta4990
    @visheshgupta4990 Před 6 měsíci +1

    Thank you so much it is very well explained good video

  • @manikaraheja2491
    @manikaraheja2491 Před rokem +1

    Deep concepts explained in very interesting way. Thanks

  • @diamondrock4945
    @diamondrock4945 Před rokem +2

    Best of the best videos on DOM

  • @sugrivlodhi2607
    @sugrivlodhi2607 Před rokem +1

    I realy love your way of teaching

  • @andrewaghoghovwia1948
    @andrewaghoghovwia1948 Před rokem +1

    Thanks alot mate.. fully understood

  • @sumitpal8689
    @sumitpal8689 Před rokem +1

    Very good explanation, any dummies can understand the way you have explained. Awesome, keep doing this good job

  • @irshadkk9704
    @irshadkk9704 Před 9 měsíci +2

    very usefull video.thanks for the wonderfull content

  • @lifeofmrc
    @lifeofmrc Před rokem +1

    Amazing video thank you

  • @mahimagontalwar1483
    @mahimagontalwar1483 Před měsícem +1

    Thank you for your help

  • @skillfulmind960
    @skillfulmind960 Před 10 měsíci +1

    Very useful content and the explanation style is awesome .....

  • @themelodymusic1658
    @themelodymusic1658 Před 11 měsíci +1

    Amazing video!

  • @jaycodes8790
    @jaycodes8790 Před 2 lety +1

    Amazing video man!

  • @sulaimanshabbir
    @sulaimanshabbir Před rokem +1

    Thank you ❤

  • @deepaksingh9928
    @deepaksingh9928 Před rokem +1

    Superb explained

  • @siddiqajamadar2283
    @siddiqajamadar2283 Před 2 lety +1

    Thank you so much for valuable information

  • @KoushikChatterjeephp
    @KoushikChatterjeephp Před rokem +1

    Owesome explanation. Better than any paid tutorial.

  • @amindavids710
    @amindavids710 Před rokem +1

    great explanation , clear one

  • @Hrit
    @Hrit Před 10 měsíci +1

    Thank you so much

  • @asthadeepak
    @asthadeepak Před rokem +1

    Very useful tanmay
    Thanks for the video

  • @qR7pK9sJ2t
    @qR7pK9sJ2t Před 6 měsíci

    MAGICAL !!!!

  • @KeshavAggarwaltechy
    @KeshavAggarwaltechy Před 2 lety +1

    Hi Tapas,
    Found your tutorial after searching for react js, I myself is Python Django developer, I too teach stuff related to python. I wanted to enhance myself on more modular stuff in frontend part. Your videos are great help
    Great stuff
    Also Camera and background enhancement is awesome, :)
    Thank you

    • @tapasadhikary
      @tapasadhikary  Před 2 lety +1

      Thanks, Keshav 💙. Sharing knowledge is a divine thing. Great to know you contribute to the Python community 👍.

    • @GoWithLyrics
      @GoWithLyrics Před rokem

      Codeevaluation is bets for React & redux

  • @grabydeal
    @grabydeal Před rokem +1

    wow., amazing explanation

  • @billypentester
    @billypentester Před rokem +1

    best ever explanation of virtual DOM

  • @willianandrade1357
    @willianandrade1357 Před 2 lety +2

    Very good video Tapas! But to be honest, these concepts are hard to swallow... specially the diffing algorithms. I'll rewatch your video and read the docs to fully grasp the idea. Thank you for your work.

    • @tapasadhikary
      @tapasadhikary  Před 2 lety +1

      Thanks, William. Please feel free to ask ur doubts in the comments section, I'll try responding as well 😊

    • @willianandrade1357
      @willianandrade1357 Před 2 lety +1

      @@tapasadhikary The first question I have is about the diffing algorithms you talked about. You taught me how they work but didn't name them. So, if I understood correctly there's: a diffing algorithm specially for changes on root elements and their content, another one specially for changes in attributes (this one I didn't quite understand) and another one for listing content and list elements. And all of them only work in JSX, since all of this is because of the DOM and Virtual DOM shenanigans. Is this right?

    • @tapasadhikary
      @tapasadhikary  Před 2 lety +1

      Yes all respect to JSX as that is what constructs Virtual DOM and renders.
      The second one is if the root doesn't change, it compares for the attribute change. That's where diffing happens again!

  • @prashlovessamosa
    @prashlovessamosa Před rokem +1

    Thank you sir

  • @education24carat
    @education24carat Před rokem +1

    Great lecture

  • @surajchaudhary1162
    @surajchaudhary1162 Před rokem +1

    Became ur fan 🥰
    The way u explain 🔥🔥

  • @jatilyadav4000
    @jatilyadav4000 Před rokem +1

    Amazing video

  • @fithamlakfikrie4657
    @fithamlakfikrie4657 Před rokem +1

    Great explanation !

  • @praptipandey7771
    @praptipandey7771 Před 10 měsíci +1

    Really good explanation

  • @vishalkuwar6579
    @vishalkuwar6579 Před 7 měsíci +1

    Useful video 👍

  • @tahreenbanu2812
    @tahreenbanu2812 Před rokem +1

    Very nice explanation....

  • @anushasurakala5975
    @anushasurakala5975 Před 4 měsíci +1

    Thank you

  • @sakinamosavi1104
    @sakinamosavi1104 Před 2 lety +1

    very helpful thanks

  • @akshaypatil8393
    @akshaypatil8393 Před rokem +1

    Yes sir it is vary useful knowledge you provide. sir please make video about Routing.

  • @sunilgeorge8864
    @sunilgeorge8864 Před 10 měsíci +1

    Good explanation brother. Keep rocking. Also put a video on React Fibre and Stack

  • @sapnasawai5199
    @sapnasawai5199 Před rokem +1

    It's really very useful

  • @estleexin7584
    @estleexin7584 Před 5 dny +1

    thank you

  • @shortme9374
    @shortme9374 Před rokem +1

    Liked, Subscribed. Thank you sir for making such clear and informative video.

    • @tapasadhikary
      @tapasadhikary  Před rokem

      Thanks a lot. It’s motivating

    • @shortme9374
      @shortme9374 Před rokem +1

      @@tapasadhikary if possible then remove that rolling subscribe button which comes below the video. it diverts the attention.

    • @tapasadhikary
      @tapasadhikary  Před rokem

      Will take care from new videos

  • @nourrahim5556
    @nourrahim5556 Před rokem +1

    YOU are greateeeeeeeeee

  • @user-gi9bn3hf4k
    @user-gi9bn3hf4k Před 9 měsíci +1

    This video is providing much clarity abut the DOM working, but since you displaying like ,subscribe, and the bell icon at the bottom of page is distracting to user.
    I suggest you to that it can be showed only once at the time of video starting.
    NOTE: Good videos automatically gets subscribed.

    • @tapasadhikary
      @tapasadhikary  Před 9 měsíci +1

      In fact, I have removed it altogether in my recent videos... Thanks for going through and as you liked it, I believe you have subscribed too 😄

  • @naruto5437
    @naruto5437 Před rokem +1

    excellent

  • @devT44
    @devT44 Před rokem +1

    Sir, what is heuristic algorithm? Where does it fits in the entire process? Is it same as diff algorithm?

  • @adarshjaiswal7334
    @adarshjaiswal7334 Před rokem

    What do you mean by saying in-memory object and how is it different from the real DOM obj?

  • @arankengineer7947
    @arankengineer7947 Před 10 měsíci

    sir, why do not we use ordered list instead of ul , it can tell specific order of change and no need for key

  • @rashedmia7849
    @rashedmia7849 Před 5 měsíci +1

    I am waiting for Javascript advance course with dsa.❤❤❤

    • @tapasadhikary
      @tapasadhikary  Před 5 měsíci +1

      That's a good ask... I will start on it after my ongoing course.

  • @random2059
    @random2059 Před rokem +1

    Please reply 🙏🙏🙏
    So react show us illumination of actual Dom just to save computational power and under the hood it slowly update the actual Dom time to time by algorithms set
    ????
    so getElement by Id , getElement by class goes away 😂

    • @tapasadhikary
      @tapasadhikary  Před rokem

      It's conceptually the same but handled in memory instead of tweaking the actual DOM. Think it like, you have data store and you have replicated some portion of it in memory and perform actions on it than doing it on the DB directly.
      DOM methods like getElementbyxxx stays but as React is declarative(please watch the secret sauce video of React series) so it abstracts way interacting with those low level APIs directly.
      Thanks for watching 💛

  • @GoWithLyrics
    @GoWithLyrics Před rokem +1

    when you asked for special attention in video, you also started poping subscribe and like popup's...great clap for you

    • @tapasadhikary
      @tapasadhikary  Před rokem

      That must be a pleasing coincidence 😀. I hope you liked the content, though.

    • @GoWithLyrics
      @GoWithLyrics Před rokem +1

      @@tapasadhikary yes content is very good…i understood about VD

  • @bishwajeetpandey1570
    @bishwajeetpandey1570 Před rokem +1

    I have a doubt at 10:15 You said if parent component states changes then react will mark all it's child components changes .
    Now suppose if parent component have a use state and that use state is only used by a one child component and there are others child elements but they don't use this useState they are simply static components.
    And latter on when the parent use state changes due to some event will it's all child component who is not using the useState will also be marked as changes to new virtual dom and will be re-rendered on the screen.
    If yes then where is the performance optimization in this scenario ?

    • @tapasadhikary
      @tapasadhikary  Před rokem +1

      > Now suppose if parent component have a use state and that use state is only used by a one child component and there are others child elements but they don't use this useState they are simply static components.
      Here are a few terminologies we need to understand. Child never gets Parent's state. A component's state is private to itself. One way the state value gets passed to child is using the props(which is not same as the state). So if A passed the props to B and B doesn't pass to C, the prop change from A to B will impact only B except the case the B itself changes in such a way the it has be teared down and built again.
      On top of this we can bring optimization for cases where the props is a heavily computed value or something that doesn't change often. Those cases we can think using the memo. However, it shouldn't be used often without considering if we really need it.

    • @bishwajeetpandey1570
      @bishwajeetpandey1570 Před rokem +1

      @@tapasadhikary thank u so much

  • @chromepos
    @chromepos Před 2 lety +1

    please, do redux tutorial

  • @ashishprasad2949
    @ashishprasad2949 Před rokem

    DOM Api is provided by browser, not JS

    • @tapasadhikary
      @tapasadhikary  Před rokem

      Yes these APIs are not core part of the language, however available as wrapper JS Web APIs developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model

  • @nawarajluitel9171
    @nawarajluitel9171 Před 2 lety +1

    Thank you sir