Learn to Code: How React.js Works

Sdílet
Vložit
  • čas přidán 28. 08. 2024
  • Learn more advanced front-end and full-stack development at: www.fullstacka...
    This talk explains various elements of how React.js works. It goes over the virtual DOM, the diffing algorithm, optimizations that the diffing algorithm uses to speed up the process. There is also a bit on some tools that you can use to optimize and speed up your React app.

Komentáře • 75

  • @codeisawesome369
    @codeisawesome369 Před 5 lety +4

    ITT: people shitting on this guy's explanation b/c of a couple mistakes - "MVC React" and "Gandolf" (yikes). The rest of the explanations are actually accurate, super concise, and gave me direction to go look up some extra material which really aided my understanding of how React works under the hood! For the people annoyed about the nervous delivery, just watch on 2x, it's still quite legible.

  • @albertofunk1167
    @albertofunk1167 Před 4 lety +12

    Loved the BF and DF examples! Really cool, actual CS in practice lol

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

    This was a great explainantion. No one's mentioned that it's just doing a really optimized JSON diff. And that context makes sense with the lifecycle tools. And that last debugging package is great to know. Thank you!

  • @sujanpokharel4627
    @sujanpokharel4627 Před 4 lety +6

    pretty good explanation! I used to think that React is only view, but now believe that internally it is uses MVC. I am satisfied with the explanation.

  • @songlining
    @songlining Před 6 lety +6

    This is the best React explanation I have seen, thanks!

  • @nitishhardeniya8871
    @nitishhardeniya8871 Před 5 lety +1

    Just what I was looking for. So summarized explanation on Virtual DOM.

  • @rravithejareddy9026
    @rravithejareddy9026 Před 7 lety +5

    In depth, Perfect , Technical

  • @laurelineparis5407
    @laurelineparis5407 Před 3 lety

    I've been looking for talk like this for a while, thanks for sharing this very intuitive explanation !!
    Hope to find more ( I'm gonna explore your talks :) )

  • @ninjaturtle11754
    @ninjaturtle11754 Před 5 lety +16

    he so nervous, it makes me nervous, but the explanation of what React does with the DOM and Virtual DOM is pretty well done. The diffing is explained in a pretty straightforward fashion.

    • @ozkaa
      @ozkaa Před 3 lety

      he wasnt even that nervous, he did a great job. don't be a jerk all your life bro

    • @ninjaturtle11754
      @ninjaturtle11754 Před 3 lety +3

      ozkaa he sounds nervous, just a fact, I am not a jerk all my life, thanks for the advice

  • @mohitkumaris
    @mohitkumaris Před 3 lety +5

    React isn’t an MVC framework.
    React is a library for building composable user interfaces. It encourages the creation of reusable UI components which present data that changes over time.

    • @mrkevinlui
      @mrkevinlui Před rokem

      If you zoom into the details of React, it can be broken down into MVC tiers and that makes sense. I think your idea of MVC might be the traditional 3-tier app of V being client, C being middletier, and model being the database.

  • @krazybubbler
    @krazybubbler Před 4 lety +2

    This is just what I needed. Thank You for this great presentation!

  • @pushkalboganatham5476
    @pushkalboganatham5476 Před 6 lety +10

    Very informative. Diffing algorithm, React DOM to Browser DOM updation explained very well.
    React as MVC is wrong.

  • @sergeymordeev8206
    @sergeymordeev8206 Před 6 lety +3

    One small remark, O(n) is not an optimization. It is an heuristic based on provided assumption that returns you some sub-optimal solution. Optimization is something different. Optimization is a "hint" to known algorithm to make it faster. For instance, if one would choose using O(n^3) algorithm which really finds the minimal set of changes then optimization could be a hint to this algorithm. However, it will give you the optimal solution. Another example could be Minimax. The result of Minimax does not change if you give it the "hint" of alpha-beta pruning. [Optimization in compiler theory is something different [optimization means here "better solution"], but intuitively it is the same. Compilation result, i.e. machine (or code) should be the same either compiler worked with optimization hints or not (at least in theory). Two produced machines are equivalent regardless of their sizes or execution speed. Compiler returns the optimal solution. That is the equivalent machine to source]. Terms are important because of their meaning. Juggling terms makes you speaking the bird language. Sometime people cease to understand you. Спасибо и удачи. Лайк.

    • @sasidharreddy7840
      @sasidharreddy7840 Před 2 lety

      R u saying O(n3) is the optimal solution....and if we include some extra conditions then we can make up a O(n) sol?

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

      @@sasidharreddy7840 The short answer is "no". TL; DR; Leave React aside. I will try to explain on fingers... The first thing we have is a "problem". The outcome of it is a "solution". In algo you may have "optimal" and "suboptimal" solutions. "Optimal" in other words means "exact". "Suboptimal" in other words means "good enough for a given problem". The way to the solution is "algorithm". Say, you want to sort some array of strings (names of customers, for example). There will be _only one_ optimal solution for a given input (alphabetically sorted names). You can’t go below n * log(n) [i.e., omega of] in sorting if it is based on comparisons (there is a proof). Nevertheless, you might have an optimization while comparing strings. If within a string you have precalculated value of its hash, in the comparison you might not to go char by char but first to conclude whether they are equivalent or not and only then drop to comparison whether one is greater or less than another. You will save a time if you have a lot of equal strings. The algorithm remains exactly the same! Just some additional info to help it. Now, what if I am saying that most people don’t care about exact sorting in names, and it is enough to have only two (or three) letters of names sorted and about others nobody cares. This is a heuristic. So, can we do better from the time perspective? Oh, yeah! The game has been changed. Now what we can do is to use Bucket sorting. For each two (or three) letter permutations we will have a bucket (say, "aa" -> 0, "ab" -> 1, ..., "zz" -> 26^2 - 1). So, now, it is O(n). In the first step we insert a name to the appropriate bucket which is O(n), in the second step, we will go over the buckets and first and put into the list which is O(n) since the number of buckets do not depend on the input and at most there will be N entries. This is suboptimal but it is good enough for the problem (and much faster in many cases). React trees comparison is different, but it is the same ;-)

  • @rajdeepchandra9807
    @rajdeepchandra9807 Před 5 lety +1

    Very informative video man. Loved the way you showcased the perf tools implementation

  • @AhamedImran
    @AhamedImran Před 7 lety +60

    I have rarely heard React called an MVC library. How accurate is this?

    • @Svsuperstud222
      @Svsuperstud222 Před 7 lety +18

      Ahamed Imran I believe React is only the 'view' part of the MVC.

    • @SARCASMOOO
      @SARCASMOOO Před 6 lety +1

      would you use react and angular together if you wanted a multi page website?

    • @dusanjovanov
      @dusanjovanov Před 6 lety +13

      No, the library itself,internally is structured as mvc

    • @vsakaria
      @vsakaria Před 6 lety

      I agree

    • @iadityaverma
      @iadityaverma Před 6 lety +3

      No, two libraries competing to control and make changes to the DOM is a bad idea.

  • @sanjivchavan7685
    @sanjivchavan7685 Před 6 lety +4

    Why we not directly update the updated nodes in browser DOM rather than creating virtual DOM n comparing it again with browser DOM??

    • @XCSme
      @XCSme Před 6 lety +5

      sanjiv chavan Because every change to the DOM will trigger a reflow as he mentioned which is really slow. You want to make all your changes at once and also you want to minimize the number of changes that you make. He also mentioned that even reeading from the actual DOM might trigger a reflow, so you might trigger the reflow during the diffing phase.

    • @sanjivchavan7685
      @sanjivchavan7685 Před 6 lety +2

      Thanks.

  • @cristef
    @cristef Před 3 lety

    This is gold, man ! Thank you !

  • @prateeksharma1047
    @prateeksharma1047 Před 7 lety +1

    Really Informative video for a beginner like me.

  • @geekcubiclesl8834
    @geekcubiclesl8834 Před 3 lety

    good explanation.Thank you

  • @liquidgoldCN
    @liquidgoldCN Před 7 lety +1

    Great content, thankyou!

  • @SSchithFoo
    @SSchithFoo Před 5 lety +1

    Its not an MVC architecture based library. It uses Flux architecture with one directional dataflow.

  • @pushkalboganatham5476
    @pushkalboganatham5476 Před 6 lety

    Can you please provide the references for the Browser DOM update slide.

  • @damonwu9658
    @damonwu9658 Před 5 lety

    Good stuff, thanks

  • @adamkenton2585
    @adamkenton2585 Před 6 lety +3

    Did he really wrote "Gandolf" (2:01)

  • @nayeem9236
    @nayeem9236 Před 7 lety +1

    Awesome information!

  • @MylesGmail
    @MylesGmail Před 5 lety +1

    Ty

  • @ranesh237
    @ranesh237 Před 5 lety

    A virtual DOM is created "completely from scratch" every time 2:40? I thought that a "new" tree is created only when the root elements are not of the same type (eg. span and div)

  • @fullStackInKannada
    @fullStackInKannada Před 3 lety

    Nice!

  • @rajniprakash6418
    @rajniprakash6418 Před 4 lety

    Where does Virtual DOM store in React?

    • @SanjayKrishnaA
      @SanjayKrishnaA Před 4 lety +1

      rajni prakash czcams.com/video/NEcWgDcGYoQ/video.html in this video you have your answe

  • @notyournormaldev1419
    @notyournormaldev1419 Před 2 lety

    Intro seems wrong

  • @kduisheev4355
    @kduisheev4355 Před 3 lety

    Great speech, though. But React is not an MVC

  • @Tunispy
    @Tunispy Před 5 lety +1

    React isn’t an MVC -____-

  • @vladimirlazarevic4255
    @vladimirlazarevic4255 Před 2 lety

    React isnt MVC!

  • @DeViLTh0rn
    @DeViLTh0rn Před 3 lety

    Basicly react is papaDOM 🥴

  • @mattmarkus4868
    @mattmarkus4868 Před 5 lety

    I thought React is just UI (views).

  • @HenriZava
    @HenriZava Před 7 lety +11

    I cringed hard when you said React was MVC, sorry, brah... you lost me there

    • @Ukr123
      @Ukr123 Před 6 lety

      oh yes, me too.

    • @dazzaondmic
      @dazzaondmic Před 6 lety +9

      What he meant was that the library itself is structured as MVC. He did not meant that React is used to build MVC apps.

    • @ergusto
      @ergusto Před 6 lety +3

      Then you completely misinterpreted what he was saying...

  • @abdulmateen9037
    @abdulmateen9037 Před 5 lety

    MVC and react what the hell

  • @alterego3110
    @alterego3110 Před 5 lety

    That is probably the most stupid explanation of MVC I have ever heard. What makes me sad is that is “academy” which supposed to teach new devs who doesn’t yet have a bs filter.

    • @vojtechno0452
      @vojtechno0452 Před 4 lety

      I believe that he was talking about how the library is structured itselft. "react is whats called a model-view-controller, it's the architecture of the library. What that really means that it splits up the controll of whole process into three components." That are his words and after that he is talking about model as core of react where is the virtual DOM built. Maybe I misunderstood it, can you explain me why is this the most stupid explanation? I don't know, but if you would look on react as single application you see that MVC desing pattern can be applied or seen in this structure. I'm relatively new in this, so your answer could help me a lot.

  • @battlefieldtroopersEA
    @battlefieldtroopersEA Před 4 lety

    Boy he's getting nervous

  • @Fahad-zv9rr
    @Fahad-zv9rr Před 6 lety +1

    he seems nervous voice is cracking maybe he needs react for his MVC model lol!

  • @relaxandnostress3625
    @relaxandnostress3625 Před 5 lety

    10 minutes of wasting time for nothing. Couple of hours to do almost nothing. This is React.

  • @fullstackacademy8400
    @fullstackacademy8400 Před 4 lety

    This a very well explained insightful of how react manages vdom to optimism dom re rendering