Optimizing Rendering Performance in React

Поділитися
Вставка
  • Опубліковано 20 сер 2022
  • We are going to use some performance optimization techniques to fix re-rendering issues in our React app that we discovered after performance profiling using React Developer Tools. React Hooks such as useCallback and memo play a big role here. Let's see how they can help here.
    ======⚡⚡⚡======
    Get a 20% discount on Brilliant.org (to learn Science, Technology, Engineering, and Math): brilliant.sjv.io/kjVO2z
    ======⚡⚡⚡======
    🙌 Become my Patreon and get exclusive perks: / softdevdiaries
    💼 Follow me on LinkedIn and drop me a message if you'd like: / gusgadirov
    💻 Also, let's connect on GitHub: github.com/gusgad
    📚 Resources:
    React Docs on Optimizing Performance: reactjs.org/docs/optimizing-p...
    And don't forget to subscribe for more videos like this 😊
    #react #javascript
  • Наука та технологія

КОМЕНТАРІ • 104

  • @SoftwareDeveloperDiaries
    @SoftwareDeveloperDiaries  Рік тому +22

    Obviously such optimizations are not necessary with a small number of re-rendered children as long as they are not too heavy. But at what point does memoizing become important? 100 items, 1.000 items or maybe 100.000 items? Share your thoughts here ✌

    • @kasemalolo5587
      @kasemalolo5587 Рік тому +1

      I want to ask
      if I have a lot of element and put them in memo function Will it cause me memory problems?

    • @GuestUser-vf9qe
      @GuestUser-vf9qe 7 місяців тому

      Try to have a large form of inputs. And control this form via Formik library for validation of user input. Probably (or even highly likely) you'll face some issues with unnecessary re-rendering...

  • @shy6489
    @shy6489 11 місяців тому +2

    mind-blowing, that's what i was searching for a very long time 🔥🔥

  • @maximus4510
    @maximus4510 Рік тому +5

    I like this channel it deserves more subscribers🔥
    you're very calm and your explanation while coding is so clear and straight to the point.
    Thank you for your quality content!

  • @muhammadumar5385
    @muhammadumar5385 Рік тому +1

    This helps get a deeper insight, very helpful. At least for a beginner like me. Keep up the good work.

  • @rohan7011
    @rohan7011 Рік тому +2

    the best useCallback usage and example!

  • @JenJHayden
    @JenJHayden 8 місяців тому +3

    This was a great video. I am brand now to full stack development. Days old. I looked up a video he mentioned to learn about profiling and performance to speed up a build. I looked up some stuff and I go here to your video. The problem for me is I think I am a little too new to full appreciate it yet. I took notes on everything you said and I have bookmarked this. Thank you.

  • @UsmanTheDev
    @UsmanTheDev Рік тому +1

    It was very helpful, thanks for your efforts

  • @AdamFiregate
    @AdamFiregate 5 місяців тому

    Great summary and presentation! Thank you.

  • @felixdziekan7335
    @felixdziekan7335 Рік тому

    Thx for the info will try that later!

  • @persianman72
    @persianman72 8 місяців тому

    You saved my time with this video, thank you!

  • @tikamikas3245
    @tikamikas3245 7 місяців тому

    Massive thank you!! You explained this perfectly and helped me solve an extremely annoying bug I’ve been dealing with 👏🏼

  • @mrunalvaidya388
    @mrunalvaidya388 Рік тому

    Watched your 10-15 videos(1st day), amazing Stuff and beautifully explained!!!!

  • @germanmartinezsolis9543
    @germanmartinezsolis9543 Рік тому

    Thanks bro I'm gonna use this advices for my further project

  • @faridul.hassan
    @faridul.hassan Рік тому

    Thank you for this awesome tutorial.

  • @costaszeimpekis994
    @costaszeimpekis994 Рік тому +1

    Very good analysis, great work

  • @rubylnic
    @rubylnic 4 місяці тому

    thank you for the great example of real life usage of these hooks! It's so precious among other explanations

  • @stephenfoster6308
    @stephenfoster6308 4 місяці тому

    Really useful video!

  • @multiverse915
    @multiverse915 Місяць тому

    Bro explained useMemo and useCallback hook in a much easy manner 👏👏

  • @ichigoplayss376
    @ichigoplayss376 11 місяців тому

    Wow, Thanks a lot bro. Now I understand it

  • @mostafabrazi4228
    @mostafabrazi4228 Рік тому

    Well explained, good job👍

  • @archiee1337
    @archiee1337 11 місяців тому

    Cool stuff, thanks

  • @kimberlyrojas3421
    @kimberlyrojas3421 Рік тому

    Really helpful, thank you!

  • @acearvingando6848
    @acearvingando6848 Рік тому

    well explained 👍 appreciate your content

  • @bustopgamer5802
    @bustopgamer5802 Рік тому

    Great job

  • @kiadtisuk8857
    @kiadtisuk8857 Рік тому

    That is helpful for my work, Thanks for this vdo

  • @jorgejorge8878
    @jorgejorge8878 7 місяців тому

    Dude, more! First video I watched and I loved it

  • @andregomes7232
    @andregomes7232 Рік тому

    Amazing content! thanks

  • @davidcunha7615
    @davidcunha7615 4 місяці тому

    Thanks :)

  • @easifier
    @easifier 10 місяців тому

    thank you for this quite helpful info 👍🏻

  • @devcode9715
    @devcode9715 Рік тому

    Great job 👏

  • @havefun5519
    @havefun5519 Рік тому

    Thanks for the video.

  • @yaakovhassoun8965
    @yaakovhassoun8965 4 місяці тому

    I've seen code like this in my codebase at work and didn't really get why it was necessary, this kinda makes a lot of sense

  • @ToastRusk
    @ToastRusk 10 місяців тому

    This was soooo good.

  • @friendsfair9283
    @friendsfair9283 3 місяці тому

    It was a good video.
    If you create a playlists on performance optimization, that would be great❤

  • @VictorZamanian
    @VictorZamanian 7 місяців тому +1

    But was the memo() of the child input components necessary after the useCallback() addition? Was the callback the only issue, or was memoization of the components themselves also necessary?

  • @zainkhas93
    @zainkhas93 Рік тому

    Quality content!

  • @hillelspivakov3140
    @hillelspivakov3140 Рік тому

    Hi, great video. What theme are you using for your vscode?

  • @randompointlessness2766
    @randompointlessness2766 7 місяців тому

    Thanks ! If I knew this, I would have saved my last job 😅

  • @prasannabiswas681
    @prasannabiswas681 15 днів тому

    sir can you do a same playlist for nextjs also need some glimpse of how senior software devs are writing code and folder structure in nextjs with scalability for future propects.

  • @keerthanachar
    @keerthanachar Рік тому

    Thank you

  • @PraveenKumaran-wh5gn
    @PraveenKumaran-wh5gn Рік тому

    Good One Bro..

  • @mohdsahil226
    @mohdsahil226 Рік тому

    very well explained!
    Would you please explain virtual DOM and how it updates the RealDOM?

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  Рік тому

      Hey mate! I put it on my list, but in the meantime I found this insightful article, maybe it could help you :)
      blog.logrocket.com/virtual-dom-react/

  • @mase-ob1vf
    @mase-ob1vf Рік тому

    KING

  • @user-ut4hj7kc1t
    @user-ut4hj7kc1t Рік тому

    And what about the context? Is there a way to improve performance of that? Because since context update one of its values, the whole value gonna be considered as a new one, and all of the components that have hooked useContext will be rendered Iven they have memo on them

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  Рік тому +2

      Thanks for a great question. I think this might be useful:
      stackoverflow.com/questions/57030018/react-context-with-hooks-prevent-re-render

  • @netssrmrz
    @netssrmrz 9 місяців тому

    Nice video about a very common issue. Personally, issues like this is why I believe React needs to go the way of the dodo. Devs shouldn't assume that giving up control over when to render is going to magically make everything simple.

  • @suryakumara3360
    @suryakumara3360 Рік тому

    Hi, why not putting id, and value in callback dependencies ? so it will be triggered when the id or value changes.

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  Рік тому

      Unless I misunderstood you, this way it will still rerender the whole component.

    • @suryakumara3360
      @suryakumara3360 Рік тому +1

      @@SoftwareDeveloperDiaries Got it, I don't code in hand.

    • @jagjot1697
      @jagjot1697 Рік тому +4

      id and value are probably of type 'String' or 'Number', which are both primitive types (includes string, number, boolean etc.) in JS. On each re-render of the parent, anything which is not a primitive data type - it could be an array, a function, or an object - all these are re-created (re-assigned a new reference/location/address in the memory) by the parent component because these are referenced by memory. All the primitive values are not re-created and hence, those do not change on the parent's re-render, which is why we don't need to 'cache' primitive values.

  • @abrhamkindie5499
    @abrhamkindie5499 День тому

    sorry bro , can you give me some thing for my project.
    my mernstack project brings some featurs late. so what my be the solution or what is the problem

  • @vaibhavsalve2024
    @vaibhavsalve2024 4 місяці тому

    Helpfull video. I Nee help.

  • @rjwhite4424
    @rjwhite4424 2 місяці тому +1

    I can't wait for React 19's compiler to come out so I don't have to bother with this.

  • @mohammadnoushadsiddiqi2550
    @mohammadnoushadsiddiqi2550 11 місяців тому +1

    This will not help if we have like 15 - 20 input, radio, uploader, switches.
    Because using usecallback for all will be a problem.
    memorization technique comes with a cost.

  • @oleksandrluchytskyi6867
    @oleksandrluchytskyi6867 Рік тому

    can we pass parameters to the useCallback((id: number) => () => setSelectedId(id),[]); ?

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  Рік тому +1

      Yes, you can:
      beta.reactjs.org/reference/react/useCallback

    • @oleksandrluchytskyi6867
      @oleksandrluchytskyi6867 Рік тому

      @@SoftwareDeveloperDiaries ah… this example works for me, thanks 👍 e.g. (I need to call useCallback for each list item in a loop, but it’s not allowed)

  • @anjanakaruna4095
    @anjanakaruna4095 Рік тому

    my god! why we dont use these things in our code... thanks for sharing! open some new areas to study.

  • @juliansyah4byte57
    @juliansyah4byte57 Рік тому

    You get my sub and turn on bell

  • @hund1267
    @hund1267 Рік тому

    Handler shouldn't recreate if you lift it above the component, or?

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  Рік тому

      Great point, it won't indeed! There are different opinions on this approach as well as small implications tho: stackoverflow.com/a/62925172

  • @coolmind2476
    @coolmind2476 2 місяці тому

    Just wondering why react doesnt do this optimizazion by default?

  • @Amamamamwnwb
    @Amamamamwnwb Рік тому

    Don’t set the editor to dark mode unless you set browser too. With screen bliking black and white, my eyes hurt. Thanks for great video though.

  • @symphony86
    @symphony86 Рік тому

    I never have to think about all these doing angular or vue.. never have any issue with performance or lagging.. only react.. whyyyy

  • @timelimitexceeded0
    @timelimitexceeded0 Рік тому

    Why not just take out the function out of the component instead of using useCallback

    • @SoftwareDeveloperDiaries
      @SoftwareDeveloperDiaries  Рік тому +1

      Indeed! There are different opinions on this approach as well as small implications tho: stackoverflow.com/a/62925172

  • @bradyfractal6653
    @bradyfractal6653 Рік тому +1

    I think you mispronounced “use Svelte” 😂

  • @AkioJunichiro
    @AkioJunichiro Рік тому +1

    Seems interesting but you speak wet, it's hard to focus