Learn React Hooks: useCallback - Simply Explained!

Поделиться
HTML-код
  • Опубликовано: 13 май 2023
  • Join The Discord! → discord.cosdensolutions.io
    Source Code → github.com/cosdensolutions/co...
    In this video we will learn about React hooks, starting with useCallback. This powerful React hook will allow you to fix your performance problems by memoizing a function and only re-computing it when necessary. You will learn how to identify performance problems from functions causing sub-components to re-render, how to memoize the functions using React's useCallback hook, and how to use the dependency array to control exactly when and how your function updates.
    In this new React world, hooks are here to stay, so it's best to learn them! In this tutorial I demonstrate the useCallback React hook, and I explain it very simply and in a way that is easy to understand. Enjoy!

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

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

    Hey everyone! I just launched 🚀 Project React, which is a course that teaches you React by building a real-world project. It goes way beyond what you see in these videos and walks you through step-by-step on how to build a big and complex application with React! You can check it out here: cosden.solutions/project-react

  • @heybran_
    @heybran_ Год назад +207

    Best react educator found on youtube! Agreed everyone?

  • @lexsemenenko7044
    @lexsemenenko7044 11 месяцев назад +22

    Clean and clear explanation with examples on what and why for us to clarify the ideas behind the hook. Again, nailed! Appreciated.

  • @JakeLuden
    @JakeLuden 11 месяцев назад +13

    Genuinely the best useCallback tutorial I’ve seen, probably the best video I’ve seen regarding hooks in general. Incredible explanation and demonstrations!

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

      damn, thanks for saying that! Really means a lot 🤙

    • @atomvandermerwe3613
      @atomvandermerwe3613 11 месяцев назад

      I 100% agree with @Jakezaruba, this video explained it perfectly.

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

    This is the cleanest and clearest explanation of useCallback ever!!!

  • @user-be3ri8gf1p
    @user-be3ri8gf1p Месяц назад +1

    Best hooks tutorial I've encountered so far! Thanks 🔥

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

    you explain useCallback so simple man, really appreciate.

  • @manojmrpd
    @manojmrpd Месяц назад

    You are really a great educator. The best react tutorials found on RUclips! Very Appreciated @Cosden Solutions

  • @CalltheWei1020
    @CalltheWei1020 8 месяцев назад

    Love how you explain the whys and what really happens behind the scenes. Thanks and much appreciated

  • @ahmadbenchakhtir5787
    @ahmadbenchakhtir5787 28 дней назад +2

    The truth is: i watched two tutorials about UseCallback from great people talking my native language -Arabic-, but i didn't get the whole idea properly. now i do. Thank u.

    • @amrhesham3135
      @amrhesham3135 28 дней назад +1

      زيك ي حبيب اخوك والله ❤✌️

    • @ahmadbenchakhtir5787
      @ahmadbenchakhtir5787 28 дней назад

      @@amrhesham3135 🤣🤣🤣🤣🤣🤣♥ مرحبا مرحبا

    • @ahmadbenchakhtir5787
      @ahmadbenchakhtir5787 27 дней назад

      @@amrhesham3135 🤣🤣🤣🤣🤣♥

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

    You are a serious teacher. You tested your code truly before publishing this video, I think. I've read many articles about useCallback and their code did not work correctly coz they did not use 'memo'. Thanks so much. Your video brings us true value.

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

      I didn't know about the memo either ! Thanks very much.

  • @noahmilliken4259
    @noahmilliken4259 3 месяца назад

    Props to Cosden for not bombarding us with some 15 second intro branding. Down to business, love it.

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

    Great video for React devs at any level. I'd forgotten that a React component that takes in a function from its parent will re-render even if the variables in that function haven't changed. Not obvious until you explained it so well. You also made it super simple and clear that useCallback memoizes a function like useMemo memoizes a variable, and that helps us minimize unnecessary re-renders.Thanks!

  • @gmjitendra
    @gmjitendra 8 месяцев назад

    you are very clear concept wise. No need to follow any other videos on react hooks. really liked all your videos. Thanks and much appreciated

  • @whiterabbitdev
    @whiterabbitdev 6 месяцев назад

    cheers dude, none of that "learn this in 3 minutes bs" you explain everything nice and clearly!

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

    Just discovered these today - and they're so well presented! These are things I use at work every day and you've done such a great job in explaining the benefits and pitfalls of each of these react hooks! Definitely pointing any new engineer over to your channel to learn/understand them

  • @tingwen1713
    @tingwen1713 3 месяца назад

    Hey! Just wanted to say that I've been going through your Learn React Hooks playlist and it's been so helpful. Thank you for making this content. You're a great educator!

  • @rajeshmaydev
    @rajeshmaydev 3 месяца назад

    the words you picked "freeze in time". Really helped me wrap the idea of it after many months of doubt

  • @__shubhamtiwari
    @__shubhamtiwari 4 месяца назад

    Bhai sahab matalab ekdam gajab padhaya yaar, dil jeet liya dost ❤

  • @vivekkumar-pc1xy
    @vivekkumar-pc1xy 6 месяцев назад

    Great video, well explained. Everything is now crystal clear

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

    Just a small add @2:30, its not that in react functions are different, its that they are referenced type in js, very well explained, really helpful thankyou

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

    The last example was very clever. Thank you sir.

  • @shamimhossain551
    @shamimhossain551 7 месяцев назад

    Ahh! you make my day. Was in a maze whole day about the using of useCallback. You've just come up with a propper salvation. Thanks ❤

  • @shubham.verma-dev
    @shubham.verma-dev 10 месяцев назад +3

    Nicely explained. I tried to understand from other videos as well, but this is really good. Now I am done with my doubts.

  • @catalincatalin4101
    @catalincatalin4101 8 месяцев назад

    We really needed someone make this hooks simple. Thanks

  • @fhkodama
    @fhkodama 5 месяцев назад

    Oh, finally a good explanation about this hook! You got a subscriber with this video! Thanks!

  • @radhiarahmani9523
    @radhiarahmani9523 Месяц назад

    Very well explained! Thank you so much

  • @ProfessionalClickers
    @ProfessionalClickers 9 месяцев назад

    Finally I understood useCallback ❤️ Thanks a lot!

  • @PradeepManek
    @PradeepManek Месяц назад

    Thank you brother you explain this topic very well.

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

    Your explain saved my life. U just got a new subscriber. Thanks.

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

    By far this is rhe best explanation have watched many many tutorials, but you explained it in very simple terms 🎉ty

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

    Awesome explanation, man! very, very clever!

  • @ASOCMARCTKD
    @ASOCMARCTKD Месяц назад

    Excellent explanation, thank you 😇

  • @kisuhara7844
    @kisuhara7844 4 месяца назад

    literally the best react tutor thank you for your videos

  • @viliuxsas
    @viliuxsas 7 месяцев назад

    I am happy that I found this channel! Thank you for very clearly explanation about React hooks and because of you I improved my knowledge.

  • @coolme7437
    @coolme7437 5 месяцев назад

    Thanks, this really is my last useCallback tutorial.

  • @aleksandrgolyk3787
    @aleksandrgolyk3787 3 месяца назад

    Great explanation 🎉🎉🎉 i was so struggling with understanding this topic. Thank you🎉🎉🎉

  • @attouyassine1056
    @attouyassine1056 4 месяца назад

    Appreciate the way you explained it, thanks

  • @VijayVibhuteFlautist
    @VijayVibhuteFlautist 4 месяца назад

    Love it! Appreciate the way you explained everything. ❤

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

    Very clear explanation!

  • @Jam....
    @Jam.... 6 месяцев назад

    Excellent clear explanation thank you.

  • @WaseemAhmad-mf3wh
    @WaseemAhmad-mf3wh 3 месяца назад

    Thank you for your clear explanation ❤

  • @saikumar.reach99
    @saikumar.reach99 12 дней назад

    Helped me understand callbacks it was tough earlier

  • @cat_demon4405
    @cat_demon4405 9 месяцев назад

    Underrated channel! subscribed

  • @ahmetzeren6878
    @ahmetzeren6878 6 месяцев назад

    great explanation thank you. no blank spaces left

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

    Awesome explanation. Thanks!

  • @dilshadazam880
    @dilshadazam880 7 месяцев назад

    You deserve atleast 1 million subscribers. Please keep making such videos

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

    omggg Great explanation. Thank you bro

  • @dylcodes
    @dylcodes Месяц назад

    Great video, thank you!

  • @antimrevapati8992
    @antimrevapati8992 4 месяца назад

    Thank you so much for making these easy to understand videos. The most important thing you did was first intruduce the problem and then explain what the topic is and how can we solve this issue using this topic, this is a wonderful strategy to follow. Thanks again!

  • @2029leandro
    @2029leandro 3 месяца назад

    Perfectly explained!

  • @Za-xh9tj
    @Za-xh9tj 3 месяца назад

    Expected to learn useCallback, instead I learned how react rerender, memo, and usecallback works. Amazing.😄

  • @peirama2
    @peirama2 5 месяцев назад

    Man, i follow and watch the videos of many tech youtubers and i have seen a ton of tutorials from many of them. This single video is the best tutorial of any concept i have ever seen. Tons of respect!

    • @cosdensolutions
      @cosdensolutions  5 месяцев назад

      Thank you for the kind words!

    • @peirama2
      @peirama2 5 месяцев назад

      @@cosdensolutions thank you for the many “aha” moments

  • @alangraton2000
    @alangraton2000 7 месяцев назад

    Dude, your channel is the bomb. Thanks for the vids ^-^

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

    Good job explaining!

  • @shabeeeb6400
    @shabeeeb6400 8 месяцев назад

    you earned a sub :) great explanation

  • @rgchroniclestv
    @rgchroniclestv 9 месяцев назад

    Really a big help. Thanks

  • @tigranharutyunyan7674
    @tigranharutyunyan7674 6 месяцев назад

    Enjoyed very much

  • @MudassirKhan-sx9jy
    @MudassirKhan-sx9jy 9 месяцев назад

    so clear. thank you ♥

  • @aliksayfullin3278
    @aliksayfullin3278 3 месяца назад

    Great explanation 👍

  • @legend_749
    @legend_749 9 месяцев назад

    awesome explaination, pls continue this series

  • @briandacallos4234
    @briandacallos4234 9 месяцев назад

    I'm shocked how he explained it very well than anyone could. Automatic subs!

  • @sidkan9251
    @sidkan9251 8 месяцев назад

    you got a new subscriber
    thanks man

  • @OXIDE777-is6gs
    @OXIDE777-is6gs Год назад

    Awesome man! thanks a bunch!

  • @samahgad241
    @samahgad241 5 месяцев назад

    thanks alot, very happy to know your channel🌹

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

    Great explanation

  • @umairiqbal1483
    @umairiqbal1483 9 месяцев назад

    Thanks. It really helped.

  • @abhinavdhama3014
    @abhinavdhama3014 8 месяцев назад

    Amazing explanation on hooks ❤❤❤❤

  • @maryannegichohi7063
    @maryannegichohi7063 4 месяца назад

    Amazing tutorial

  • @atakan8570
    @atakan8570 7 месяцев назад

    best teacher ever

  • @zul.overflow
    @zul.overflow 4 месяца назад

    clean and clear 👍

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

    you earned a new subscriber

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

    Great to see you here I followed you on tiktok. So great work keep going forward

  • @TheMakeupmonika
    @TheMakeupmonika 11 месяцев назад

    love you man ! thank you so much

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

    Amazing! thanks

  • @user-dq1to7hg2n
    @user-dq1to7hg2n Месяц назад

    Excellent!

  • @SahilKashyap64
    @SahilKashyap64 20 дней назад

    Thank you for this

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

    Done thanks clear explanation

  • @mralextacy
    @mralextacy 7 месяцев назад

    awesome tutorial

  • @diggerdog001
    @diggerdog001 5 месяцев назад

    15:32 When u put 'users' in arr dep i really thought them why we need use Callback if we started from where our problem starts. And you began explain 😀

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

    Thanks ❤

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

    Thanks buddy 😊😊

  • @nyomansunima
    @nyomansunima 8 месяцев назад

    Good explaination. Now i know it

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

    Great explanations sir the only concern is I watched 5 ads each containing 2 ads(which I can't skip) 😂😂😂

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

    brilliant

  • @iamparmjeetmishra
    @iamparmjeetmishra Месяц назад

    thanks

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt 5 месяцев назад

    Awesome

  • @mephesh
    @mephesh 26 дней назад

    perfect

  • @talidamg
    @talidamg 14 дней назад

    Thank you for the clear explanation, Darius. Can you maybe share the shuffle function with us? It's not in the source code. :D

  • @bismarckkaine2700
    @bismarckkaine2700 8 месяцев назад

    You're awesome

  • @smchap9474
    @smchap9474 7 месяцев назад

    To understand, with this particular example we did actually undo all the purpose of useCallvack since users will be different when shuffled, right?

  • @capt_vj
    @capt_vj 3 месяца назад

    nice

  • @Akhillbj
    @Akhillbj 11 месяцев назад

    When you say, onChange prop is different from the previous do you mean like actual props of the searchProps or values of the existing props?

    • @cosdensolutions
      @cosdensolutions  11 месяцев назад

      the `onChange` function, although it's the same function that does the same code (values don't really matter here), it'll be considered different because it'll be a different instance of the function. Different instance means it's just a copy of the function, but it's not the same one in memory. So even though it looks the same and does the same thing, it is a separate entity, thus it will cause the props to evaluate as not equal

  • @ahallock
    @ahallock 4 месяца назад

    Thanks for this clear explanation. As a React beginner, I feel like the DX is pretty terrible. You have to litter your code with all these hooks and remember what's changing and where. I worked with Bacon.js before and the mental model is much better, in my opinion, for handling state changes over time. React feels like spaghetti to me.

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

    Please do a useReducer tutorial 👏👏👏👏🙌🙌🙌🙌🙏🙏🙏🙏

  • @matthewweclar
    @matthewweclar 3 месяца назад

    EPic

  • @anonim1468
    @anonim1468 4 месяца назад

    If we add another state and update it still will get memoized component to rerender. This is because arrays are reference types in JS and in every component render it gets a new reference so you will get new reference for callback function as well

  • @giannizamora7247
    @giannizamora7247 3 месяца назад

    One of the things I noticed at 15:05 is that 'alex' shows but If you typed "james" the console log users[0] would have still been alex and that's because before our input changed alex was the first person in that list.

  • @nitinmali7430
    @nitinmali7430 4 месяца назад

    Thanks Cosden. One question. What's the difference example onChange={handleSearch} and onChange={()=>handleSearch()} ?

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

      they're the same, but the second way you'll have to pass all of the arguments manually, if you have some. If you pass it like the first way, they'll get automatically passed

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

    After you add 'users' as a dependency to the useCallback, if you press shuffle, would the search component still not rerender?

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

      Yes it does, but that is what you want. You don't want to prevent a render, you just want to control when it happens. So if there was another piece of state that would change, then it wouldn't re-render. You only want to re-render when what it depends on changes, and nothing else!

    • @cordial
      @cordial 7 месяцев назад

      @@cosdensolutions cheers. great video as always btw.