useMemo Explained | React Hooks useMemo Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024

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

  • @sergiorey2049
    @sergiorey2049 2 ปีที่แล้ว +17

    One of the very best videos I have seen about React and JS, I'm sure a lot of developers have come across issues like these not knowing exactly the cause and what to do, I wish I had seen this a year ago lol, great stuff Dave keep it up!

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

    If you're not careful, your React apps can suffer from performance issues when you have a function that takes a moment or two to complete processing. By applying the useMemo React hook, you can avoid this kind of processing bottleneck. Just starting with React? I recommend my full 9 hour React course tutorial video here: th-cam.com/video/RVFAyFWO4go/w-d-xo.html

  • @TradingBloke
    @TradingBloke 7 หลายเดือนก่อน

    you are literally the best javascript teacher on youtube or udemy or online , in few minutes you taught what others teach in 1 hour

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

    Still can't believe this is a free course !!! Dave, you are an outstanding teacher !!!

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

    Thanks man I got fullstack developer job because of you, I just can't thank you enough

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

      Love to hear this kind of feedback! Congrats!!! 💯🚀🙌

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

    Thank you very much. I had big trouble understanding the useCallback and useMemo hooks even though i have seen endless tutorials.
    But finally yours helped me understand it!
    I had big problem understanding if a usecallback should always be used alongside usememo. Now I finally understood

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

    That's really awesome. Anyone can understand the real difference between useMemo and useCallback. Thanks a lot Dave😍😍

  • @ahmad-murery
    @ahmad-murery 2 ปีที่แล้ว +4

    Really informative video,
    Things can get tricky if you don't know how React renders components,
    therefore, it important to choose dependencies carefully and think twice before deploying code to a production server,
    Thanks Dave,

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      You're welcome Ahmad. I'm glad to see your comment 🙏

    • @ahmad-murery
      @ahmad-murery 2 ปีที่แล้ว

      @@DaveGrayTeachesCode I couldn't resist,
      with all of my troubles your videos keep challenging me,
      Have a nice day my friend

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

    This is an important advanced stuff for anyone who develope a largre react app

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

    This is one of the best explanations on what useMemo and useCallback are. You did an excellent job with this video - thanks!

  • @ifeanyichimbo
    @ifeanyichimbo 6 หลายเดือนก่อน

    Thanks so much Dave for your great lessons. Your explanations make it possible for a nub to get it.

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

    you're the best tech teacher in youtube!

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

    Good example Dave, immediately understood the use of UseMemo.

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

    The best video i could find on this topic. After a few days of searching, finally i could undestand. Thansk a lot mr dave ♥️🙏

  • @davidirawan3083
    @davidirawan3083 9 หลายเดือนก่อน

    always you are the best for explained some tutorial.Thanks dave

  • @chunli680
    @chunli680 2 ปีที่แล้ว +1

    Thanks for the great content as always! Really like the way you explain things, especially with the examples you gave :D

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

      You're welcome! Thank you for the kind words 🙏💯

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

    subbing because your teaching style is lovely. thank you for your great work Dave!

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

    I sincerely appreciate your efforts. The second use case of useMemo is explained very clearly without using React.memo(). Thank you very much🙂. I had a doubt when you were explaining that useEffect(( )=>clg('New Number), fib) was not executed again because fib is a primitive type and hence fib is the same during every render of the FC. I thought it was not executed because fib's value is not changing when we enter the value for randomInput. But I have better understanding then before thank you very much again🙂🙂🙂🙂🙂🙂🙂🙂

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

    Thank you very much Mr.Dave

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

    Thanks for the clear explanation!

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

    Clear explanation. Able to understand the real usage. Thanks alot

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

    Another great tutorial explaining React concepts, useMemo() in this case. Thanks, Dave
    {2022-10-19}

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

    Hey form Algeria , you are doing a great work , keepit that way

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

    Best tutor ever!

  • @h-robs
    @h-robs 2 ปีที่แล้ว

    Thank you! Such good explanations and examples

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

    Piece of gem. Nice explaination.

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

    You are a legend 🙏🙏

  • @user-hu9eo7iw3y
    @user-hu9eo7iw3y 5 หลายเดือนก่อน

    Thank you so much.

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

    Love your tutorials. 😍😍

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

    Great tutorial!! It might be stupid question but I don't get why fib function doesn't need dependency. we don't need to put 'n' in dependency?
    const fib = useCallback((n) => {
    return (n

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

      useCallback provides a memoized function. It is not calling the function and therefore n is a parameter placeholder and not a value at this point. We apply useCallback to avoid redefining a function on every render. useMemo does call a function. Note the userNumber argument needs to be in the dep. array for useMemo.

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

    Great video!

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

    Thank you for that video! :-)

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

    Thank you for this amazing tutorial.

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

    Great video, very easy to understand

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

    This is awesome!

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

    very helpfull thank you so much

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

    Is there a reason that the fib function is in the dependency array of useMemo and not useCallback? I can see the computed value "userNumber" being in the dependency array of useMemo, but why is the function there also?

    • @oortcloud210
      @oortcloud210 6 หลายเดือนก่อน

      I wondered this too - I know its inside the function but it seems it is entirely static so why would it need to be regarded as a dependency?

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

    Hey Dave, great video, I just have one question. When you move fib from outside the component to in the component, why do you have to add fib to the dependencies of the useMemo call? That function is in scope for the function passed to useMemo and fib is never going to change, so can you leave it out of the dependencies of the useMemo call?

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

      Good question, Paul! When defined inside the functional component, the function will always be created again. It looks the same to us, but it will not have the same memory reference. I'm referring to what is called referential equality. This applies to objects, arrays, and functions. Therefore, we memoize the function with useCallback. Now it should have referential equality, but it is still a dependency of useMemo when we create the fib number. You will get a warning/complaint in your console from React if you do not add it to the dependency array. Of course, you could ignore that or put in a comment to disable the eslint for the next line.

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

    Thanks

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

    So, if an function is defined in a separate file and is used in a component then there is no need to use useCallback hook. Right?
    Then what is the practical use case of useCallback?

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

      This video is about useMemo, but for your questions about useCallback, I have a video here: th-cam.com/video/FB_kOSHk1DM/w-d-xo.html

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

    Great explaination.👌

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

    Good stuff. Thanks from Ukraine.)

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

    Nice one

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

    Hi Dave, do you run online courses on Udemy?

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

      No, but I do hope to release my own premium content in the future. I don't think I will use Udemy to release it though.

  • @moSaeedNahlous
    @moSaeedNahlous 10 หลายเดือนก่อน

    🤩🤩

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

    in the '80s, when people wrote BASIC, they had this GOTO statement and people call it spaghetti code, and they got rid of it forever, saying NEVER do that. We are now entering a new era where we need to "memo" a function, and figure out "the dependencies", wow, that's spectacular programming, even more great than "spaghetti"

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

    tnx sir

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

    Do You Know that you are the best & special ?

  • @Yusuf-ok5rk
    @Yusuf-ok5rk 2 ปีที่แล้ว

    nice introduction lol