How Does React Actually Work? React.js Deep Dive #1

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024

Комментарии • 269

  • @Aliena92
    @Aliena92 2 года назад +5

    I wasn't expecting the background music. Probably the first coding tutorial with music. Worked like magic. Thank you :)

  • @ffking1357b
    @ffking1357b 3 года назад +127

    Great content! I think this is the only video available in youtube that talks about the React principle and at the same time is friendly to beginners. Keep up the good work. The video serves really well for people who wanna dive into the source code of React while have no idea where to start.

  • @StryKhymorodnyk
    @StryKhymorodnyk Год назад +3

    It is the greatest explanation I have seen! I say it, as I have just kind of ended self-learning JavaScript and was wondering about React.js's hard-mode. It is good that you show it like that, because when I have seen the other's 'let's create-react-app' and so on, I just felt as if I forgot all I knew!
    I have to switch, due to war. Even my 2 diplomas are just for fun. That is where English and German are useful.
    Thank you, Philip! My best friend lives in Prague since 2008. He helps me in learning, but I couldn't have understood React, even with his help! You have helped! Great

  • @Sagarclips
    @Sagarclips Месяц назад +1

    great video Philip! Keep rocking

  • @deep_swamp
    @deep_swamp 2 года назад +2

    Awesome explanation with one caveat at 7:30. The diffing algorithm has a complexity of _O(n)_ which does *not* mean that the number operations will be smaller than (n). Instead it means that the number of operations will be (

  • @k303k
    @k303k Год назад +2

    Your channel is a work of art.I'm new to your channel.I've been learning Reactjs for about like 4 months and i was looking for like how React works behind the scenes .Your channel is a masterpiece.Thank you so much.Can we expect like Nextjs series Deep dive series if you have times sir?Thank you....

  • @hichamelkamouni9910
    @hichamelkamouni9910 Год назад +1

    actully this one of the greatest videos about react. thanks for this amazing content , can't wait to see more.

  • @harshitadhingra225
    @harshitadhingra225 2 года назад +2

    The Best 'React Under the Hood' explanation!!

  • @timjobs9072
    @timjobs9072 2 года назад +1

    omg, much of information in the video killed confusions, really helped a lot.❤❤❤

  • @pq6688
    @pq6688 2 года назад +3

    Brilliant content. World-class content. Keep it up Philip, it's amazing.

  • @billchen4923
    @billchen4923 2 года назад +1

    Super awesome & fantastic lessons, rarely encounter such a deep dive React tutorial on RUclips.

  • @hariharan3469
    @hariharan3469 Год назад +1

    Loving this DEFFING ALGORITHM. Thanks mate

  • @zhenghongjiang5862
    @zhenghongjiang5862 2 года назад +1

    Best content! clear and concise, I've never seen. thanks for your sharing!

  • @nextleveltech267
    @nextleveltech267 7 месяцев назад +2

    Thank you... Really informative 👍

  • @bjornstabell2970
    @bjornstabell2970 3 года назад +2

    Great video series! Very much needed :) One thing I'd love to understand a bit better is component instances. What is the relationship between elements and instances? Where does React keep its references to the component instances? In the element tree somewhere? The 'ref'?

    • @PhilipFabianek
      @PhilipFabianek  3 года назад +1

      The relationship between React elements (the ones that have the function type which returns the nested elements) and instances is 1-to-1. For each element that describes a component, there exists a component instance.
      About the second question: Instances exist in memory. We as React developers can access class instances using the 'this' keyword or lifecycle methods. This works because an instance of a class component is an actual instance of the class afterall. We can access functional component instances using React hooks. We can also create refs.
      What you are asking is how does React access them or how are they stored internally. The answer is that this is 1 level below what we are talking about. It has a lot to do with React Fiber, which I covered in the next episode of this deep dive (ruclips.net/video/0ympFIwQFJw/видео.html). Fibers keep actual references to component instances in the 'stateNode' property. I think this answer on Stack Overflow is what you are looking for: stackoverflow.com/a/58968770/8699608 The function in the answer can retrieve the component instance from the actual element in the DOM.

  • @DiaryOfMuhib
    @DiaryOfMuhib Год назад +1

    Awesome. Keep up the good work

  • @kiefer8101
    @kiefer8101 2 года назад +1

    Subscribed!
    More React internals content please!!

  • @nguyentruong1812
    @nguyentruong1812 Год назад

    Thank you Philip, you cleared a lot of my confusions :))

  • @zoltancaputo9562
    @zoltancaputo9562 Год назад +1

    Amazing! Tks for share.

  • @lilithfirefly3727
    @lilithfirefly3727 Год назад +1

    Great work. Thank you for the detailed explanation 💜

  • @39_ganesh_ghodke98
    @39_ganesh_ghodke98 Месяц назад +1

    very informative video. Thanks

  • @flosev75
    @flosev75 Год назад +1

    Philip's slavic pronunciation allows me to understand everything what he says

  • @knrking007
    @knrking007 2 года назад +1

    Wow man what an explanation.... No one taught me like this🤗🤗 thank you

  • @programmingwithnit5308
    @programmingwithnit5308 Год назад +1

    Thank you brother 🙏🙏

  • @GiftOkiefe
    @GiftOkiefe Месяц назад +1

    Great content

  • @shaleenchowdhary
    @shaleenchowdhary 8 месяцев назад +1

    Great Video

  • @anshumansharma4509
    @anshumansharma4509 Год назад +1

    Great🙌

  • @pranavkochhar9352
    @pranavkochhar9352 2 года назад +1

    AMAZING CONTENT!

  • @fteiyp
    @fteiyp 2 года назад +1

    How are you printing out the virtual DOM of your app like you do at @6:53?

    • @PhilipFabianek
      @PhilipFabianek  2 года назад +1

      I simply log it to the console like I did previously in the video.

    • @fteiyp
      @fteiyp 2 года назад

      @@PhilipFabianek ahh thank you!

  • @codefinity
    @codefinity 2 года назад +2

    Great info. The vocal delivery does make me drowsy though. 😪 :)

    • @PhilipFabianek
      @PhilipFabianek  2 года назад +1

      Thank you for watching! I am working on it 🙂

  • @joeblack8843
    @joeblack8843 Год назад +1

    Their is a function named "lifecycle", i wonder what these team was thinking

  • @dengjudeng9790
    @dengjudeng9790 3 года назад +1

    Awesome !

  • @Stefan-xm9qb
    @Stefan-xm9qb 7 месяцев назад +1

    And how does this deep knowledge improve my skills as a react developer? I managed to successfully use react for many projects without this knowledge.

    • @PhilipFabianek
      @PhilipFabianek  7 месяцев назад +1

      That is a good question. I was also using React for several years before learning how it actually works. I think it gives one some satisfaction to have a rough idea of how the technology that is being used works. Additionally, I think there are some practical takeaways, for example knowing how keys work and why they are important, etc.

    • @Stefan-xm9qb
      @Stefan-xm9qb 7 месяцев назад

      I agree there is some satisfaction that I felt. And yes absolutely the thing with the keys is very important. I actually looked up some of my code and I found out I used the key incorectly:
      I used index as key 😱
      {sectionsData.map((section, index) => (
      ...
      ))}
      But I guess this would be much more efficient (if the sectionsData changes like things get prepended for example):
      {sectionsData.map((section, index) => (
      ...
      ))}
      But do I really need to understand how the diff function works in order to apply that knowledge?
      I also could have just read this react documentation:
      Keys tell React which array item each component corresponds to, so that it can match them up later. This becomes important if your array items can move (e.g. due to sorting), get inserted, or get deleted. A well-chosen key helps React infer what exactly has happened, and make the correct updates to the DOM tree.
      Rather than generating keys on the fly, you should include them in your data:
      Pitfall
      You might be tempted to use an item’s index in the array as its key. In fact, that’s what React will use if you don’t specify a key at all. But the order in which you render items will change over time if an item is inserted, deleted, or if the array gets reordered. Index as a key often leads to subtle and confusing bugs.
      Similarly, do not generate keys on the fly, e.g. with key={Math.random()}. This will cause keys to never match up between renders, leading to all your components and DOM being recreated every time. Not only is this slow, but it will also lose any user input inside the list items. Instead, use a stable ID based on the data.
      Note that your components won’t receive key as a prop. It’s only used as a hint by React itself. If your component needs an ID, you have to pass it as a separate prop: .
      Source: react.dev/learn/rendering-lists
      Anyway now I started learning flutter and I wonder if flutter Widgets rendered as lists also need keys?
      I did some research and you can also provide keys in flutter to optimise re-rendering: www.flutterclutter.dev/flutter/tutorials/2023-04-08-how-to-use-keys/
      But I think if I had read the react docs instead of understanding how this Diff function in react works I wouldn't have also assumed that in flutter there is a similar thing. So I don't understand how that knowledge of the react Diffing algorithm helps me.
      So maybe if you are trying to learn a similar but different technology maybe if you understand it in depth how the first technology works under the hood it may be helpful or may not?
      And I guess for static lists that don't change it's unnecessary to add keys. That's something I wouldn't have known if I wouldn't understand how the Diffing function in react works.
      So to summarise it is useful to have this deep knowledge for optimising and that knowledge can also be mapped to different technologies?
      Did I miss something? I still am not satisfied with my own answer.
      By the way if you could start learning React from beginning like someone would erase your memories and you would time travel in the past would you first just learn to "use" react for couple weeks and then start look into how it works under the hood or the other way around?
      @@PhilipFabianek

    • @Stefan-xm9qb
      @Stefan-xm9qb 7 месяцев назад

      I agree there is some satisfaction that I felt. And yes absolutely the thing with the keys is very important. I actually looked up some of my code and I found out I used the key incorectly:
      I used index as key 😱
      {sectionsData.map((section, index) => (
      ...
      ))}
      But I guess this would be much more efficient and avoid some bugs:
      {sectionsData.map((section, index) => (
      ...
      ))}
      But do I really need to understand how the diff function works in order to apply that knowledge?
      I also could have just read this react documentation:
      Keys tell React which array item each component corresponds to, so that it can match them up later. This becomes important if your array items can move (e.g. due to sorting), get inserted, or get deleted. A well-chosen key helps React infer what exactly has happened, and make the correct updates to the DOM tree.
      Rather than generating keys on the fly, you should include them in your data:
      Pitfall
      You might be tempted to use an item’s index in the array as its key. In fact, that’s what React will use if you don’t specify a key at all. But the order in which you render items will change over time if an item is inserted, deleted, or if the array gets reordered. Index as a key often leads to subtle and confusing bugs.
      Similarly, do not generate keys on the fly, e.g. with key={Math.random()}. This will cause keys to never match up between renders, leading to all your components and DOM being recreated every time. Not only is this slow, but it will also lose any user input inside the list items. Instead, use a stable ID based on the data.
      Note that your components won’t receive key as a prop. It’s only used as a hint by React itself. If your component needs an ID, you have to pass it as a separate prop: .
      Source: react.dev/learn/rendering-lists
      @@PhilipFabianek

    • @spht9ng
      @spht9ng 2 месяца назад

      @@Stefan-xm9qb Filling in knowledge gaps is important. Gives you more tools to solve complex problems.

  • @TheZayzoo
    @TheZayzoo 2 года назад +47

    This video made me realize that I'm standing on the shoulders of giants whenever I'm developing in React. Facebook devs are magicians

  • @prathameshkhetre1494
    @prathameshkhetre1494 7 месяцев назад +2

    00:00 Understanding the basics of React
    01:50 A React component is a class or function that outputs an element tree.
    03:44 React elements, components, and instances
    05:42 React uses a virtual DOM to efficiently update the real DOM
    07:38 React's Diffing algorithm relies on two important assumptions
    09:33 React's reconciliation algorithm explained
    11:30 React renderers generate and insert elements during reconciliation.
    13:25 React communicates with renderers using dispatchers.

  • @rahuljoshi8331
    @rahuljoshi8331 Год назад +2

    We don't need to import React now while working with JSX. What changed?

    • @Ramesh-js
      @Ramesh-js 10 месяцев назад

      Correct! it is misassumption!

  • @kevinfreeman9652
    @kevinfreeman9652 2 года назад +14

    Philip this was awesome. I have been an educator for over 15 years and love watching others present information. Your use of the calming background music, imagery, and the pace of your voice definitely put my mind in a place to absorb the content easily. Please continue to bring us more information. Instantly subscribed!!!

  • @zahidshaikh3122
    @zahidshaikh3122 8 месяцев назад +4

    Before this, I was working BLINDLY on React and any other library or framework that is out their. This very content opened my EYES 👀.

  • @Isagi__000
    @Isagi__000 3 месяца назад +1

    Nice. Where have you been?. Hope you r doing well. Do some videos once in a while if possible

  • @hematw
    @hematw 3 дня назад +1

    Nice video I learnend new things thank you man

  • @youssefmahmoud6268
    @youssefmahmoud6268 2 года назад +1

    Thanks for your efforts, if you can just remove the music it will be great.thanks again.

  • @sanjuthreddy6435
    @sanjuthreddy6435 Год назад +1

    amazing content but maybe remove the background sound or reduce the volume jst a request :)

  • @mrwick2op
    @mrwick2op 10 месяцев назад +1

    Great video , thanks brother it helped alot to understand react better.

  • @christianolsson8644
    @christianolsson8644 Год назад +5

    I have worked as a React developer for four years and I never understood why you have to import React and neither why you can't use the index as a key. Very good and clear explanations. I will have an interview for a React job on monday and this definitely helps me! Thank you! 😃

  • @omarpervez5657
    @omarpervez5657 8 месяцев назад +1

    Have to say bunch of words about this video but not have much time to do it. You did a great job that I can't explain. Keep it up your great work. Have subscribed your Channel 👍

  • @1minuteunity759
    @1minuteunity759 4 месяца назад +2

    Great Video!

  • @nuvat3853
    @nuvat3853 2 года назад +1

    Hi about List key, i think maybe in some occasions, for example a paginated list with same size of elements in every page, use index its not a bad idea because you can optimize number of mounts. If you use id the react mount and rerender but if you use index the only that algorithm can check its that are differents props so only re-render. Obviously depends on the situation, what do you think about this?

    • @PhilipFabianek
      @PhilipFabianek  2 года назад

      Assuming the list is paginated after the indexes are generated and the order of items doesn't change, using indexes as keys shouldn't lead to any bugs, but I don't understand how would using ids as keys be slower. It is also a good practise to use id as a key, because if in the future you implemented sorting or maybe filtering, your application would suddenly be buggy.

  • @vishalkuwar6579
    @vishalkuwar6579 10 месяцев назад +1

    wohh what a informative video. Just great!!!!. I dont Know why you stopped making videos but you should make more videos/

    • @PhilipFabianek
      @PhilipFabianek  10 месяцев назад

      Thank you, I am currently very busy but there will be videos in the future

  • @aes0p895
    @aes0p895 2 месяца назад +2

    great job. very good info in a short time.

  • @AleySoundz
    @AleySoundz 10 месяцев назад +1

    Thank you for this video it was very helpful.

  • @naturalguardian5885
    @naturalguardian5885 9 месяцев назад +2

    Awsome work ! keep going this !

  • @lisa2034
    @lisa2034 2 года назад +1

    Great content. Only thing the BGM is kinda distracting.

  • @ngocthile1001
    @ngocthile1001 Год назад +1

    great explanation. Thanks so much

  • @viralpasad5222
    @viralpasad5222 2 месяца назад +1

    This explanation can be understood by a 5 year old as well! Genius!!!

  • @이범진-z6i
    @이범진-z6i 3 месяца назад +1

    awsome video thanx from south korea!!

  • @digitalsparrow_8599
    @digitalsparrow_8599 2 месяца назад +1

    Amazing explanation for such a complex subject!!!

  • @lancecourse
    @lancecourse 2 часа назад

    Thanks for this info. I have learned a lot. Soon, I will explain it to new learners in much detail. Thanks

  • @VKY-XLR8
    @VKY-XLR8 Год назад +1

    11:25 can some one name other examples of ' and so on' in 2nd point...also what is 'platform specific' ?

    • @PhilipFabianek
      @PhilipFabianek  Год назад

      Take a look here: github.com/facebook/react/tree/main/packages/react/src

  • @sonphung3512
    @sonphung3512 2 года назад +1

    how amazing you are, can i proposal a video about how SSR in Nextjs work ?

    • @PhilipFabianek
      @PhilipFabianek  2 года назад +1

      Thank you for watching! I will consider making a video about that in the future.

  • @bruh_5555
    @bruh_5555 Год назад +1

    amazing content! still watching in 2023

  • @DemystifyFrontend
    @DemystifyFrontend 9 месяцев назад +1

    This is really awesome content .

  • @19jnz08
    @19jnz08 2 года назад +2

    I've switched from Angular to React. This video is very helpful. Thank you for sharing your knowledge ;)

  • @Generally2310
    @Generally2310 11 месяцев назад +2

    Thanks

  • @marcframe7449
    @marcframe7449 2 года назад +2

    great video! I love the 3blue1brown kinda style applied to programming.

    • @PhilipFabianek
      @PhilipFabianek  2 года назад +1

      Thank you very much! I have watched quite a few videos from 3b1b and they had an impact on me.

  • @ВладиславБояркин-д9т
    @ВладиславБояркин-д9т 2 месяца назад

    Great video! Very comprehensive material
    But at 10:40 you mentioned that two first items will be unmounted because there will be new inserted before the first one
    But neither type nor key have changed. Only children have changed. So I guess they won't be unmounted, but their props will be changed

  • @deadfire7973
    @deadfire7973 2 месяца назад +1

    excellent work! thanks!

  • @GauravYadav-rv7wx
    @GauravYadav-rv7wx 2 года назад +3

    This is gold stuff, I believe it not available any where.
    Please bring more videos like this

  • @ezwtwrziehag1736
    @ezwtwrziehag1736 9 дней назад +1

    music ruined it

  • @nghiatranthanh3806
    @nghiatranthanh3806 2 года назад +1

    Great video! Thank you

  • @zeddastra
    @zeddastra 7 месяцев назад +1

    incredible explanation!

  • @frankdearr2772
    @frankdearr2772 5 месяцев назад +1

    great topic, thanks

  • @bushbuddyplatypus
    @bushbuddyplatypus Год назад +1

    Fantastic, and great music

  • @umairqamar2672
    @umairqamar2672 2 года назад +1

    premium level content bro !

  • @trannhathao3978
    @trannhathao3978 2 года назад +1

    Thank you, now I can understand more about react

  • @zb2747
    @zb2747 Год назад +2

    Nice brief high-level overview of the source code and core deep fundamentals

  • @iShallEatChips
    @iShallEatChips 9 месяцев назад +1

    You are a damn smart man!

  • @ramanpreetsingh186
    @ramanpreetsingh186 7 месяцев назад +1

    great explanation!!!!

  • @VladimirJovana
    @VladimirJovana 2 года назад +1

    15 mins of pure beauty, thanks a lot

  • @atul7173
    @atul7173 2 года назад +2

    Thank you. Thank you very much for this video. I myself tried to dive into how react works. But I got stuck into the part where it's also mentioned in React docs that creating React element is less costier as compared to DoM elements as they are plain JS object. But I'm not able to understand this in depth why is it so. So it would be great help if you or anyone reading this can point me to some reference to this answer.

    • @PhilipFabianek
      @PhilipFabianek  2 года назад +1

      First it is important to understand that DOM manipulations are expensive (medium.com/technogise/dom-manipulation-in-browser-59b793bee559 may help you). What is probably confusing you is that React also creates DOM elements. So why is React more efficient? Because React uses the diffing algorithm. It therefore always figures out the most efficient way to mutate the DOM tree.

  • @ajeeteppakayala6788
    @ajeeteppakayala6788 2 года назад +4

    One of the best videos for those who want to dive deep into the React and the source code.

  • @uuu06222
    @uuu06222 Год назад +1

    This is amazing, I checked lots of times if I have already pressed like during watching this, thank you!

  • @chans9055
    @chans9055 Год назад +1

    Thank you for the amazing video, now I have a better understanding of React

  • @wxq521
    @wxq521 2 года назад +3

    This is so great. The explain is very simple and clear. Thanks author, you make my days much easier and saved my time.

  • @StatisticsTheory
    @StatisticsTheory 11 месяцев назад +2

    Finally! I've been looking for this series for the past week. Great stuff Philip 😁

  • @ubayabdelgadir4165
    @ubayabdelgadir4165 Год назад +1

    Thank you very much, I was wondering how react native was possible, but you elegantly explained that react is not a platform specific, and it does not actually render to HTML without another separate library 11:22.

  • @Serzes_
    @Serzes_ Год назад +1

    Thank you for your videos, those information are not easy to find on RUclips because in general people explain only how to use things without explaining it

  • @mrnenes777
    @mrnenes777 2 года назад +1

    Good video, thnks!

  • @NubeBuster
    @NubeBuster Год назад +1

    appreciated a lot

  • @MrAdityaSingal
    @MrAdityaSingal 9 месяцев назад +1

    Awesome content!!

  • @danieldesales377
    @danieldesales377 6 месяцев назад +1

    Great content!

  • @LyczeQQ
    @LyczeQQ 2 года назад +1

    Man, thank you so much for this video. I finally understand React

  • @mykolao
    @mykolao Год назад +1

    This is pure gold

  • @dovahkiin3362
    @dovahkiin3362 Год назад +1

    this is gold

  • @meetpatel8751
    @meetpatel8751 11 месяцев назад +1

    Nice video !!! 👏

  • @MrRobot-mb6rq
    @MrRobot-mb6rq 2 года назад +2

    This video deserves million views.

  • @mazdysoraya6121
    @mazdysoraya6121 9 месяцев назад +1

    Wow thanks.

  • @AiwwwA
    @AiwwwA 2 года назад +2

    This is gold

  • @leroysaldanha3849
    @leroysaldanha3849 2 года назад +1

    woooahhh! amazingg

  • @illyapelypenko3190
    @illyapelypenko3190 2 года назад +1

    Man you rock. So cool explanation!

  • @emmanuelonyebueke544
    @emmanuelonyebueke544 2 года назад +1

    You are good man