Learn to Code: How React.js Works

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ม.ค. 2017
  • Learn more advanced front-end and full-stack development at: www.fullstackacademy.com
    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.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 75

  • @codeisawesome369
    @codeisawesome369 4 ปีที่แล้ว +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 4 ปีที่แล้ว +11

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

  • @songlining
    @songlining 6 ปีที่แล้ว +6

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

  • @lancetakiguchi9756
    @lancetakiguchi9756 2 ปีที่แล้ว +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!

  • @laurelineparis5407
    @laurelineparis5407 3 ปีที่แล้ว

    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 :) )

  • @nitishhardeniya8871
    @nitishhardeniya8871 4 ปีที่แล้ว +1

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

  • @rravithejareddy9026
    @rravithejareddy9026 6 ปีที่แล้ว +5

    In depth, Perfect , Technical

  • @rajdeepchandra9807
    @rajdeepchandra9807 4 ปีที่แล้ว +1

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

  • @krazybubbler
    @krazybubbler 3 ปีที่แล้ว +2

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

  • @sujanpokharel4627
    @sujanpokharel4627 4 ปีที่แล้ว +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.

  • @prateeksharma1047
    @prateeksharma1047 7 ปีที่แล้ว +1

    Really Informative video for a beginner like me.

  • @cristef
    @cristef 3 ปีที่แล้ว

    This is gold, man ! Thank you !

  • @pushkalboganatham5476
    @pushkalboganatham5476 6 ปีที่แล้ว +10

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

  • @liquidgoldCN
    @liquidgoldCN 7 ปีที่แล้ว +1

    Great content, thankyou!

  • @sergeymordeev8206
    @sergeymordeev8206 6 ปีที่แล้ว +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 2 ปีที่แล้ว

      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 2 ปีที่แล้ว +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 ;-)

  • @geekcubiclesl8834
    @geekcubiclesl8834 3 ปีที่แล้ว

    good explanation.Thank you

  • @damonwu9658
    @damonwu9658 5 ปีที่แล้ว

    Good stuff, thanks

  • @ninjaturtle11754
    @ninjaturtle11754 5 ปีที่แล้ว +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 3 ปีที่แล้ว

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

    • @ninjaturtle11754
      @ninjaturtle11754 3 ปีที่แล้ว +3

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

  • @nayeem9236
    @nayeem9236 7 ปีที่แล้ว +1

    Awesome information!

  • @AhamedImran
    @AhamedImran 7 ปีที่แล้ว +60

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

    • @Svsuperstud222
      @Svsuperstud222 7 ปีที่แล้ว +18

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

    • @SARCASMOOO
      @SARCASMOOO 6 ปีที่แล้ว +1

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

    • @dusanjovanov
      @dusanjovanov 6 ปีที่แล้ว +13

      No, the library itself,internally is structured as mvc

    • @vsakaria
      @vsakaria 6 ปีที่แล้ว

      I agree

    • @iadityaverma
      @iadityaverma 5 ปีที่แล้ว +3

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

  • @pushkalboganatham5476
    @pushkalboganatham5476 6 ปีที่แล้ว

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

  • @sanjivchavan7685
    @sanjivchavan7685 6 ปีที่แล้ว +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 6 ปีที่แล้ว +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 6 ปีที่แล้ว +2

      Thanks.

  • @mohitkumaris
    @mohitkumaris 2 ปีที่แล้ว +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 ปีที่แล้ว

      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.

  • @MylesGmail
    @MylesGmail 5 ปีที่แล้ว +1

    Ty

  • @fullStackInKannada
    @fullStackInKannada 2 ปีที่แล้ว

    Nice!

  • @SSchithFoo
    @SSchithFoo 5 ปีที่แล้ว +1

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

  • @adamkenton2585
    @adamkenton2585 6 ปีที่แล้ว +3

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

  • @ranesh237
    @ranesh237 5 ปีที่แล้ว

    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)

  • @rajniprakash6418
    @rajniprakash6418 4 ปีที่แล้ว

    Where does Virtual DOM store in React?

    • @SanjayKrishnaA
      @SanjayKrishnaA 4 ปีที่แล้ว +1

      rajni prakash th-cam.com/video/NEcWgDcGYoQ/w-d-xo.html in this video you have your answe

  • @kduisheev4355
    @kduisheev4355 3 ปีที่แล้ว

    Great speech, though. But React is not an MVC

  • @notyournormaldev1419
    @notyournormaldev1419 ปีที่แล้ว

    Intro seems wrong

  • @DeViLTh0rn
    @DeViLTh0rn 3 ปีที่แล้ว

    Basicly react is papaDOM 🥴

  • @mattmarkus4868
    @mattmarkus4868 5 ปีที่แล้ว

    I thought React is just UI (views).

  • @Tunispy
    @Tunispy 5 ปีที่แล้ว +1

    React isn’t an MVC -____-

  • @abdulmateen9037
    @abdulmateen9037 5 ปีที่แล้ว

    MVC and react what the hell

  • @vladimirlazarevic4255
    @vladimirlazarevic4255 2 ปีที่แล้ว

    React isnt MVC!

  • @Fahad-zv9rr
    @Fahad-zv9rr 6 ปีที่แล้ว +1

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

  • @HenriZava
    @HenriZava 6 ปีที่แล้ว +11

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

    • @Ukr123
      @Ukr123 6 ปีที่แล้ว

      oh yes, me too.

    • @dazzaondmic
      @dazzaondmic 6 ปีที่แล้ว +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 6 ปีที่แล้ว +3

      Then you completely misinterpreted what he was saying...

  • @battlefieldtroopersEA
    @battlefieldtroopersEA 4 ปีที่แล้ว

    Boy he's getting nervous

  • @alterego3110
    @alterego3110 5 ปีที่แล้ว

    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 4 ปีที่แล้ว

      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.

  • @relaxandnostress3625
    @relaxandnostress3625 5 ปีที่แล้ว

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

  • @fullstackacademy8400
    @fullstackacademy8400 4 ปีที่แล้ว

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