useMemo Explained | React Hooks useMemo Tutorial

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 89

  • @sergiorey2049
    @sergiorey2049 3 роки тому +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!

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

    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  3 роки тому +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: ua-cam.com/video/RVFAyFWO4go/v-deo.html

  • @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

  • @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!

  • @rajeevranjansingh7103
    @rajeevranjansingh7103 2 роки тому +2

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

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

    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 2 роки тому

    Good example Dave, immediately understood the use of UseMemo.

  • @ahmad-murery
    @ahmad-murery 3 роки тому +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  3 роки тому +1

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

    • @ahmad-murery
      @ahmad-murery 3 роки тому

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

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

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

  • @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 ♥️🙏

  • @jsdragon6500
    @jsdragon6500 3 роки тому

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

  • @chunli680
    @chunli680 3 роки тому +1

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

  • @ArunPrabu007
    @ArunPrabu007 2 роки тому

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

  • @mostafahusany1747
    @mostafahusany1747 2 роки тому

    Thank you very much Mr.Dave

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

    Thanks for the clear explanation!

  • @appustudio8637
    @appustudio8637 3 роки тому

    Piece of gem. Nice explaination.

  • @zineddinelouzani7069
    @zineddinelouzani7069 3 роки тому

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

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

    You are a legend 🙏🙏

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

    Love your tutorials. 😍😍

  • @ivanshoshkov
    @ivanshoshkov 2 роки тому

    Best tutor ever!

  • @h-robs
    @h-robs 2 роки тому

    Thank you! Such good explanations and examples

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

    Great video!

  • @Pareshbpatel
    @Pareshbpatel 2 роки тому

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

  • @pratikdevle5830
    @pratikdevle5830 2 роки тому

    Great video, very easy to understand

  • @UnpluggedPerformance
    @UnpluggedPerformance 2 роки тому

    This is awesome!

  • @forstudy7900
    @forstudy7900 2 роки тому

    Thank you for this amazing tutorial.

  • @subhashgn1775
    @subhashgn1775 2 роки тому

    Great explaination.👌

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

    Thank you so much.

  • @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🙂🙂🙂🙂🙂🙂🙂🙂

  • @belkocik
    @belkocik 2 роки тому

    Thank you for that video! :-)

  • @pauljbarry3
    @pauljbarry3 2 роки тому

    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  2 роки тому

      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.

  • @vladserhiychuk8925
    @vladserhiychuk8925 2 роки тому

    Good stuff. Thanks from Ukraine.)

  • @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.

  • @brahimo4701
    @brahimo4701 2 роки тому

    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 9 місяців тому

      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?

  • @erictr5582
    @erictr5582 2 роки тому

    Hi Dave, do you run online courses on Udemy?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      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.

  • @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: ua-cam.com/video/FB_kOSHk1DM/v-deo.html

  • @mohammadmahdialvansaz8001
    @mohammadmahdialvansaz8001 2 роки тому

    Thanks

  • @onencanemmanuel4511
    @onencanemmanuel4511 2 роки тому

    Nice one

  • @khamzatilek9078
    @khamzatilek9078 3 роки тому

    tnx sir

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

    🤩🤩

  • @Yusuf-ok5rk
    @Yusuf-ok5rk 2 роки тому

    nice introduction lol

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

    Do You Know that you are the best & special ?

  • @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"