REACT MEMO vs USECALLBACK vs USEMEMO

2020 ж. 3 Мам.
53 705 Рет қаралды

Get 1 on 1 mentorship with me! ▶▶▶calendly.com/codingwithchaim/...
usecallback vs usememo vs memo was the question I was asking myself when I first saw them. In this video I aim to clarify what each one does and how they differ from one another.

Пікірлер
  • I would like to do a Q & A video in the near future. If you’d like me to answer your question, reply to this comment with your question, and it might just get featured!

    @CodingWithChaim@CodingWithChaim4 жыл бұрын
    • It might be a dumb question but should I at ALL times look to useCallbacks, Refs and Memo/useMemo to avoid all kind of unnecesary renders? Are those principles for delivering a solid React application? Like sometimes I will noticed these unnecesary renders in parent components on child events, this is the way to avoid that infortunate an annoying behavior? Like a few weeks ago I did notice that passing props through onChange event was messing with a login form as It was re rendering the parent (I had a setState there being called through useEffect on change of my input) and it was losing focus on EACH type event I was making, my solution was to memoized the value, set the onChange local on that input and send the value through an useCallback and have an useRef to store the value instead of a setState, and that way I made it. Typing on any input of that form wasn't causing re renders on the parent therefore I wasn't losing the focus on each key press.Sometimes I will notice that kind of silly behavior without messing with my program but I wonder if the re render as my program scales would become annoying or is affecting performance even at that low scale. prnt.sc/zx7t6b prnt.sc/zx7z1v Those are snippets of my code. Parent and Child.

      @WTHBrou@WTHBrou3 жыл бұрын
    • Usually the computations are on object arrays as big as 100-500 items which are retrieved via an api call (in rare events where such computations are not handled on server side). Will useMemo work on such arrays, where same set of object array is retrieved repeatedly from an api call? 1. Will it be treated as a changed array? 2. Is it a shallow comparison? 3. What will be the workaround in such a case?

      @shariwamalankar8278@shariwamalankar82783 жыл бұрын
  • a summary I have made for this great (!!!) video: - When parent is being changed - it is rendering itself and his children. If we don’t want to render the child if none of its props is changing, then we use: “import {memo} from “react” export default memo()” - Passing a function (declared and implemented in the parent) to the child as a prop so that the child is executing it inside. In that case the reference to that function is being changed in every parent rendering. So the “memo” is not working. we’ll wrap the function in useCallback and will not pass any dependencies because we don’t want it to ever change. - Use useMemo when you want to memoized (store in cache) the value after complex or long computation and whenever some of the dependencies, passed in that hook, is changed then it will recompute that again. Thanks Chaim from Israel :)

    @linoymiz22@linoymiz22 Жыл бұрын
    • And thank you for this concise and great summary!

      @ivanho9245@ivanho9245 Жыл бұрын
    • Thanks :)

      @sabihamohammad7770@sabihamohammad7770 Жыл бұрын
  • This is by far the MOST DETAILED and succint and SIMPLE explanation for these React hooks! Respect man! Subbed!

    @riyanshbiswas@riyanshbiswas3 жыл бұрын
    • Here here

      @CodeDreamer68@CodeDreamer682 жыл бұрын
  • Explaning referential equality blown my mind, now I'm understanding it! Got yourself a new subscriber!

    @drewstifler1440@drewstifler14403 жыл бұрын
    • Thank you! I’m so glad you find it helpful!

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • F**k, this is the most straight forward, easy to understand, and most concise explanation for all of these things.

    @briandacallos4234@briandacallos4234 Жыл бұрын
  • I was literally dying to understand these hooks so I looked at different tutorials and still didn't get it but now your simple way of explanation helped me to understand them fully so thank you, man, wish you the best. You just gained a new subscriber.

    @mahmoudhassen4463@mahmoudhassen44632 жыл бұрын
  • I googled, searching for the differences between those three functions and I couldn't understand anything at all. I watched your video and now I can see the difference clearly, thank you so much for your time recording this video. Subscribed

    @eduardozepeda1972@eduardozepeda19723 жыл бұрын
  • 6:10 useCallback explanation 9:12 useMemo explanation Very helpful video! Thanks!

    @masaokitamura@masaokitamura2 жыл бұрын
  • Finally my dought related to specially usecallback is now clearled .A big thank u sir .

    @ujjawalkapoor8342@ujjawalkapoor83422 жыл бұрын
  • Most underrated channel. You deserve more subscribers...

    @___GM___@___GM___3 жыл бұрын
  • This channel is a literal GEM. Love your explanation!

    @ogreeni@ogreeni Жыл бұрын
    • Wow, thanks!

      @CodingWithChaim@CodingWithChaim Жыл бұрын
  • DUDE! Had I discovered this video about 2 years ago! thank you so much !

    @adnantariq3346@adnantariq3346 Жыл бұрын
  • been stuck on these for months. you are an excellent tutor.

    @himanshuprasad9690@himanshuprasad9690 Жыл бұрын
  • This is pure Gold approach to make us understand complicated topics. I am subscribing you right away man. Great work .

    @prateeksharma5169@prateeksharma51692 жыл бұрын
  • This is very useful. Short and concise, straight to the point with working examples. Finally understood the use of useCallback after so long! Thanks. Subscribed!

    @ngcharnchuen4314@ngcharnchuen43143 жыл бұрын
    • Thank you! Glad you found it useful

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
    • Wouldn't using useCallback instead of useMemo also work in the last example?

      @pictzone@pictzone2 жыл бұрын
  • what great video man, I feel relieved by the amazing content here

    @rubenmartinez2807@rubenmartinez28072 жыл бұрын
  • Superb explanation, made the concepts crystal clear in such a short video! Thanks a ton!

    @arpanbanejee5143@arpanbanejee51432 жыл бұрын
  • I've had to seen many videos, under a large span of time, to actually get these three concepts as of now. Thank you!

    @jorgecaceres3840@jorgecaceres3840 Жыл бұрын
  • wow ive been stuck on this for days and it finally just clicked thanks man subscribed

    @alexparsons909@alexparsons909 Жыл бұрын
  • This was a fantastic video describing these 3 in perfect detail. Thank you

    @user-cp6lp6rq8n@user-cp6lp6rq8n6 ай бұрын
  • You told everything very clearly. It helps. Thanks

    @sumitarora6429@sumitarora64292 жыл бұрын
  • impressive video. it gives me a perfect vision of React memo Thanks. Chaim

    @topwebinar9581@topwebinar95813 жыл бұрын
  • This is pure GOLD !!! Awesome content

    @muhammadjawadurrahim4883@muhammadjawadurrahim48833 жыл бұрын
  • great explanation sir, I went through several article but never understood properly after watching this, concept got clear. Thanks

    @abhishekaryan7575@abhishekaryan75752 жыл бұрын
  • Got all my doubts cleared! Thanks a lot.

    @namanagarwal4233@namanagarwal42333 жыл бұрын
  • Hi Chaim, I really like your videos! It helps me a lot with advanced topics! THANK YOU MAN!

    @omaralsadidev@omaralsadidev Жыл бұрын
  • THis was really a precise to the point video, now I can go ahead and optimize my code. thanks a lot Chaim 🎉🎉🎉🎉🎉

    @louicoder@louicoder Жыл бұрын
  • Man believe me working in react for one year and asked so many devs, watched so many videos and read so many Blogs about these hooks, no one really able to clear my doubt until I watched your video. Thanks man thank you so much.

    @mohdbaqerhaider3440@mohdbaqerhaider34402 жыл бұрын
    • what if we use array inside usecallback does not it work same as usememo

      @lingarajhiroli965@lingarajhiroli965 Жыл бұрын
  • That was a really helpful video. Thanks Chaim.

    @jhlagado1@jhlagado13 ай бұрын
  • Awesome explanation, simple and straight to the point.

    @alexandrexp985@alexandrexp9852 жыл бұрын
  • this is the only video that made me understand memo usecallback and use memo thank you good sir

    @ezramollena7588@ezramollena75882 жыл бұрын
  • Finally I understand the difference!!! Thank you!!!

    @LeandroSimoesArt@LeandroSimoesArt2 жыл бұрын
  • Such a simple explanation. Glad I landed here.

    @arunstudd@arunstudd2 жыл бұрын
  • Best explaination for all the three things. It makes whole concept easy for me, easy to use now. 🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰

    @prashantsingh4793@prashantsingh47932 жыл бұрын
  • Picked up perfect examples. Now I feel difference between useCallback, useMemo and memo. Thanks))

    @user-rk7dm1xm3r@user-rk7dm1xm3r10 ай бұрын
  • Thank you! This was really helpful and well explained with a simple demonstration.

    @blackcoffeedevelopment3522@blackcoffeedevelopment3522 Жыл бұрын
  • Fantastic, easy to follow example! Thanks!

    @dhunsworth@dhunsworth2 жыл бұрын
  • That was lot of react in just 13 mins, THANKS A LOT

    @BharatSingh-zk8lx@BharatSingh-zk8lx2 жыл бұрын
  • Thank you so much for detailed information!

    @rasikakshirsagar5563@rasikakshirsagar55632 жыл бұрын
  • Your explanation and examples in my experience is on another level always feel skeptical until I watch yours😂.

    @mdmoinmoin8888@mdmoinmoin888811 ай бұрын
  • Ive watched a lot of coding channel over the years. This channel will blow up for sure nail everything A++ content, quality everything. If you read my comments im usually a troll so if you can get +1 from me you own the internet.

    @iliketocode6986@iliketocode69863 жыл бұрын
    • Thanks!

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • Good video, very concise. QQ for the useCallback, is the changeChildNumber function still needed? Can't the setChildNumber go straight into the useCallback?

    @dannyroberts4067@dannyroberts4067 Жыл бұрын
  • I understand it, Thank you very much! Greetings from Peru.

    @davidmariolc@davidmariolc2 жыл бұрын
  • Crystal clear explanation ❤ Subbed

    @officialabdulrehman@officialabdulrehman3 жыл бұрын
  • Your explanation and use cases were to the point

    @kamranhamid9175@kamranhamid91752 жыл бұрын
  • awesome material,, keep the good job on

    @hosseinpanahy5358@hosseinpanahy53583 ай бұрын
  • Awesome explanation. Thank you very much. More subscribers!

    @devopsdeekay8584@devopsdeekay8584 Жыл бұрын
  • Its funny I always complain about music in coding tutorials but you seemed to have done it properly =/ you got skills. hit bell button because of it ( : and good content obv

    @iliketocode6986@iliketocode69863 жыл бұрын
  • Perfectly done. Thanks😇

    @Raj00001Mr@Raj00001Mr2 жыл бұрын
  • Thank you. Very helpful. Subscribed!!

    @MrFattylee@MrFattylee3 жыл бұрын
  • Best explanation ever :) thank you.

    @magosiatanska2867@magosiatanska28672 жыл бұрын
  • You, Sir, are a wonderful man!!

    @arvindvs8934@arvindvs89343 жыл бұрын
    • Thank you that’s very kind

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • Woow.. Thank you.. Understood it well.

    @vidumini23@vidumini233 жыл бұрын
  • Excellent explanation 🚀

    @edinburghrules@edinburghrules Жыл бұрын
  • Simply amazing, thanks a lot!

    @juanchibrossa8569@juanchibrossa8569 Жыл бұрын
    • Glad you liked it!

      @CodingWithChaim@CodingWithChaim Жыл бұрын
  • the greates explanation ever!

    @osamagamal495@osamagamal4952 жыл бұрын
  • super helpful video, very well explained, thanks!

    @MrAlithom39@MrAlithom393 жыл бұрын
    • Thanks! Very glad you found it helpful

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • Subscribed, really good teacher!

    @deamorta6117@deamorta61173 жыл бұрын
    • Thank you! Welcome to the channel

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • Thanks man. it really helped. Subscribing !!

    @saienrique@saienrique2 жыл бұрын
  • thank you sir you have cleared all my doubts

    @siddheshb.kukade4685@siddheshb.kukade46852 жыл бұрын
  • Great video, I am your new subscriber!

    @user-lf8gj2lj2p@user-lf8gj2lj2p Жыл бұрын
  • Nice explanation 👍🏾

    @pranavambhore9215@pranavambhore92152 жыл бұрын
  • you are goldmine of knowldage!

    @hanibal43@hanibal433 жыл бұрын
    • thank you!

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • BEST , thank you so much

    @waqasrana5734@waqasrana5734 Жыл бұрын
  • excellent explaination sir keep uploading new videos its help us

    @subashbose2924@subashbose29242 жыл бұрын
  • 7:19 are incrementLocal and changeChildNumber gets re created every single time when App component is rendered?

    @jeetviramgama4392@jeetviramgama4392 Жыл бұрын
    • yep thats exactly it

      @CodingWithChaim@CodingWithChaim Жыл бұрын
  • Excellent explanation thank you.

    @planetmall2@planetmall23 жыл бұрын
    • You’re most welcome

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • You sir earned a sub

    @gravelessForever@gravelessForever3 жыл бұрын
  • Thanks so much, you saved me from an angry PM ❤️

    @olayemioyebanji9625@olayemioyebanji96253 жыл бұрын
    • My pleasure!

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • you are the best sir

    @r13aero@r13aero2 жыл бұрын
  • Still the best video in this topic by far

    @shreejanregmi@shreejanregmiАй бұрын
  • i always re watch this video before my interview also suggest my friends about this video

    @codewithedraak@codewithedraak Жыл бұрын
  • The music in the background really disturbs our concentration. I hope you do something about it

    @errortaker2553@errortaker25533 жыл бұрын
    • It sounds like he's rapping.

      @Joshuaomorales@Joshuaomorales3 жыл бұрын
    • @@Joshuaomorales he is rapping

      @leepoking@leepoking3 жыл бұрын
    • dude chaim has fucking bars. so chill let him spit over the beat about his react knowledge. TURN THAT SHIT UP CHAIM

      @BobbyBundlez@BobbyBundlez3 жыл бұрын
    • @@BobbyBundlez Yeah, yeah Ayo, Hooks, it's time. It's time, Hooks (aight, Hooks, begin). Straight out the fast dungeons of rap. The prop drops deep as does my state. I never render, 'cause to render is the father of great. Beyond the walls of elements, life is defined. I think of useCallback when I'm in a React City state of mind. Hope the plate got some rate. My date don't like no dirty great. Run up to the mandate and get the advocate. In a React City state of mind. What more could you ask for? The optimized prop? You complain about useMemo. I gotta love it though - somebody still speaks for the top. I'm rappin' to the package, And I'm gonna move your trackage. Lightweight, modern, compatible, like a file Boy, I tell you, I thought you were a hostile. I can't take the useMemo, can't take the component. I woulda tried to compose I guess I got no proponent. I'm rappin' to the trackage, And I'm gonna move your package. Yea, yaz, in a React City state of mind. When I was young my father had a pop. I waz kicked out without no crop. I never thought I'd see that top. Ain't a soul alive that could take my father's shop. A sexy node is quite the goad. Thinking of useCallback. Yaz, thinking of useCallback (useCallback).

      @neoesm@neoesm2 жыл бұрын
    • @@neoesm omg well that just made my morning

      @BobbyBundlez@BobbyBundlez2 жыл бұрын
  • awesome!

    @banjotola4898@banjotola4898 Жыл бұрын
  • Thank you!!

    @aashayamballi@aashayamballi3 жыл бұрын
    • You're welcome!

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • Wouldn't using useCallback instead of useMemo also work in the last example?

    @pictzone@pictzone2 жыл бұрын
  • This is gold

    @georgevinueza7249@georgevinueza72493 жыл бұрын
  • So what is the difference between useMemo and useCallback. Switching useMemo with useCallback in your example will make no difference in the behaviour. Right ?

    @the_bitcoin_guy@the_bitcoin_guy3 жыл бұрын
  • memo is a higher-order component to memoize an entire functional component. useMemo is a react hook to memoize a function within a functional component

    @harshads530@harshads530 Жыл бұрын
  • would sending setChildNumber to child break Memo same as sending changeChildNumber function?

    @paccioti@paccioti3 жыл бұрын
    • Yes it would

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • the best explanation here in youtube

    @londzon1340@londzon13403 жыл бұрын
    • Thank you! I’m glad you found this helpful

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • Shouldn't all components render with memo by default in the next React version ?

    @Rolanditou@Rolanditou Жыл бұрын
  • Really nice job! I would like to use same example but translate it for hispanic ppl into my channel. If you dont mind .And of course giving you the credit

    @felipev5607@felipev56072 жыл бұрын
    • Thank you! Yes for sure, go for it!

      @CodingWithChaim@CodingWithChaim2 жыл бұрын
  • thank you

    @yummysoup@yummysoup Жыл бұрын
  • So how are useMemo and useCallback different? They both wrap functions that get recalled from the same memory if the args haven't changed. Is it that useMemo caches the return value but useCallback does not?

    @fooked1@fooked13 жыл бұрын
    • Exactly. UseMemo caches the value returned by the function where as useCallback caches the function itself

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • very detailed explanation love your videos on react. but can you slow down a little bit.

    @macaroni976@macaroni976 Жыл бұрын
  • hello! Your content is awesome! could you explain useRef? An it would be cool to record a tutorial, how to implement advanced filtering for e-commerce web app with react/redux/redux actions. I guess, it will be interesting for your subscribers, because there are a lot of video tutorials about e-commerce apps, but they are not implemented in professional way. Thnks

    @pavel1429@pavel14294 жыл бұрын
    • UseRef is on the list as well! Please keep your suggestions coming I really appreciate them

      @CodingWithChaim@CodingWithChaim4 жыл бұрын
  • Thanks!

    @sarelvaroner8921@sarelvaroner89213 жыл бұрын
    • You’re welcome!

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • vey nice explanation new subscriber here

    @mathearts9739@mathearts97393 жыл бұрын
    • Thanks! And welcome!

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • hi, isnt it always better to usecallback while passing functions then ?

    @amoghrijal2846@amoghrijal28463 жыл бұрын
    • If you’re not using memo on the component that the function is being passed to it won’t make any difference to use useCallback. Also it’s important to remember not to optimize pre maturely. First encounter the bottle neck and then solve it

      @CodingWithChaim@CodingWithChaim3 жыл бұрын
  • But isn't it okay for the child component to rerender? As long as you don't have long calculations happening in the child component and the child node didn't change, actual changes in DOM shouldn't happen right?

    @mrSargi7@mrSargi7 Жыл бұрын
    • So a couple points here. First, you are correct that it's ok for a child component to re-render, memo is just there for you when you run into a performance issue due to excessive re-renders, but typically this wont be an issue. As for your second point, it's important to understand that once a component renders, the browser will paint. The only thing as react devs that we can control are renders, but after a render happens, the browser will paint to screen.

      @CodingWithChaim@CodingWithChaim Жыл бұрын
  • nice

    @behnammaghsoodi2632@behnammaghsoodi26323 жыл бұрын
  • be cool to share source code so we can play with it. Also if-you say source code in below thing we see your adds so you get more people seeing them (: win win

    @iliketocode6986@iliketocode69863 жыл бұрын
  • Nice

    @jassam246@jassam2464 жыл бұрын
    • Thanks!

      @CodingWithChaim@CodingWithChaim4 жыл бұрын
  • Can you please start to make real-life projects in react js and node js. (MERN) stack development I have seen people on youtube they doing just simple things but I want you to do something different which help us beginners to go to the next level. Thank you

    @iUmerFarooq@iUmerFarooq4 жыл бұрын
    • Yes absolutely! I think thats a great idea to add to the list.

      @CodingWithChaim@CodingWithChaim4 жыл бұрын
    • @@CodingWithChaimYeah, Thanks for hearing me.

      @iUmerFarooq@iUmerFarooq4 жыл бұрын
    • I've been asking @Coding With Chaim for several months already, to create such content. Tutorials are for beginners, not for senior programmers and we want to see, how projects implemented in professional way)

      @pavel1429@pavel14294 жыл бұрын
    • Yea this is on the list! I have so much to get to thanks to all the great suggestions

      @CodingWithChaim@CodingWithChaim4 жыл бұрын
  • Great example! I actually understood the concept with this video. But, why do you have music in the background when you are talking? It is distracting :(

    @shraddhapunjabi232@shraddhapunjabi232 Жыл бұрын
  • 👏👏👏👏👏

    @sudhanshuchaurasia1101@sudhanshuchaurasia11012 жыл бұрын
  • Explanations are superb! But, I would recommend removing background music when speaking

    @NayTunThein@NayTunThein2 жыл бұрын
  • Only added more questions than before lol

    @gitcat8160@gitcat81603 жыл бұрын
  • BEST BEST BEST

    @waqasrana5734@waqasrana5734 Жыл бұрын
KZhead