Тёмный

REACT MEMO vs USECALLBACK vs USEMEMO 

Coding With Chaim
Подписаться 16 тыс.
Просмотров 55 тыс.
50% 1

Get 1 on 1 mentorship with me! ▶▶▶calendly.com/c...
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.

Опубликовано:

 

8 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 184   
@CodingWithChaim
@CodingWithChaim 4 года назад
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!
@WTHBrou
@WTHBrou 3 года назад
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.
@shariwamalankar8278
@shariwamalankar8278 3 года назад
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?
@linoymiz22
@linoymiz22 2 года назад
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 :)
@ivanho9245
@ivanho9245 Год назад
And thank you for this concise and great summary!
@sabihamohammad7770
@sabihamohammad7770 Год назад
Thanks :)
@riyanshbiswas
@riyanshbiswas 3 года назад
This is by far the MOST DETAILED and succint and SIMPLE explanation for these React hooks! Respect man! Subbed!
@CodeDreamer68
@CodeDreamer68 2 года назад
Here here
@drewstifler1440
@drewstifler1440 4 года назад
Explaning referential equality blown my mind, now I'm understanding it! Got yourself a new subscriber!
@CodingWithChaim
@CodingWithChaim 4 года назад
Thank you! I’m so glad you find it helpful!
@eduardozepeda1972
@eduardozepeda1972 3 года назад
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
@mahmoudhassen4463
@mahmoudhassen4463 3 года назад
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.
@masaokitamura
@masaokitamura 2 года назад
6:10 useCallback explanation 9:12 useMemo explanation Very helpful video! Thanks!
@___GM___
@___GM___ 3 года назад
Most underrated channel. You deserve more subscribers...
@mohdbaqerhaider3440
@mohdbaqerhaider3440 2 года назад
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.
@lingarajhiroli965
@lingarajhiroli965 2 года назад
what if we use array inside usecallback does not it work same as usememo
@adnantariq3346
@adnantariq3346 Год назад
DUDE! Had I discovered this video about 2 years ago! thank you so much !
@errortaker2553
@errortaker2553 4 года назад
The music in the background really disturbs our concentration. I hope you do something about it
@Joshuaomorales
@Joshuaomorales 4 года назад
It sounds like he's rapping.
@leepoking
@leepoking 3 года назад
@@Joshuaomorales he is rapping
@BobbyBundlez
@BobbyBundlez 3 года назад
dude chaim has fucking bars. so chill let him spit over the beat about his react knowledge. TURN THAT SHIT UP CHAIM
@neoesm
@neoesm 3 года назад
@@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).
@BobbyBundlez
@BobbyBundlez 3 года назад
@@neoesm omg well that just made my morning
@ujjawalkapoor8342
@ujjawalkapoor8342 2 года назад
Finally my dought related to specially usecallback is now clearled .A big thank u sir .
@user-rk7dm1xm3r
@user-rk7dm1xm3r Год назад
Picked up perfect examples. Now I feel difference between useCallback, useMemo and memo. Thanks))
@briandacallos4234
@briandacallos4234 Год назад
F**k, this is the most straight forward, easy to understand, and most concise explanation for all of these things.
@jorgecaceres3840
@jorgecaceres3840 Год назад
I've had to seen many videos, under a large span of time, to actually get these three concepts as of now. Thank you!
@ogreeni
@ogreeni 2 года назад
This channel is a literal GEM. Love your explanation!
@CodingWithChaim
@CodingWithChaim Год назад
Wow, thanks!
@alexparsons909
@alexparsons909 Год назад
wow ive been stuck on this for days and it finally just clicked thanks man subscribed
@harshads530
@harshads530 Год назад
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
@BharatSingh-zk8lx
@BharatSingh-zk8lx 2 года назад
That was lot of react in just 13 mins, THANKS A LOT
@ngcharnchuen4314
@ngcharnchuen4314 4 года назад
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!
@CodingWithChaim
@CodingWithChaim 4 года назад
Thank you! Glad you found it useful
@pictzone
@pictzone 2 года назад
Wouldn't using useCallback instead of useMemo also work in the last example?
@topwebinar9581
@topwebinar9581 4 года назад
impressive video. it gives me a perfect vision of React memo Thanks. Chaim
@himanshuprasad9690
@himanshuprasad9690 2 года назад
been stuck on these for months. you are an excellent tutor.
@abhishekaryan7575
@abhishekaryan7575 2 года назад
great explanation sir, I went through several article but never understood properly after watching this, concept got clear. Thanks
@ezramollena7588
@ezramollena7588 2 года назад
this is the only video that made me understand memo usecallback and use memo thank you good sir
@prateeksharma5169
@prateeksharma5169 2 года назад
This is pure Gold approach to make us understand complicated topics. I am subscribing you right away man. Great work .
@jhlagado1
@jhlagado1 7 месяцев назад
That was a really helpful video. Thanks Chaim.
@miguelbarrios1962
@miguelbarrios1962 2 месяца назад
Grand Explanation!! thank you sir!
@iliketocode6986
@iliketocode6986 4 года назад
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.
@CodingWithChaim
@CodingWithChaim 4 года назад
Thanks!
@arunstudd
@arunstudd 3 года назад
Such a simple explanation. Glad I landed here.
@davidmariolc
@davidmariolc 2 года назад
I understand it, Thank you very much! Greetings from Peru.
@mdmoinmoin8888
@mdmoinmoin8888 Год назад
Your explanation and examples in my experience is on another level always feel skeptical until I watch yours😂.
@user-cp6lp6rq8n
@user-cp6lp6rq8n 9 месяцев назад
This was a fantastic video describing these 3 in perfect detail. Thank you
@LeandroSimoesArt
@LeandroSimoesArt 2 года назад
Finally I understand the difference!!! Thank you!!!
@olayemioyebanji9625
@olayemioyebanji9625 4 года назад
Thanks so much, you saved me from an angry PM ❤️
@CodingWithChaim
@CodingWithChaim 4 года назад
My pleasure!
@prashantsingh4793
@prashantsingh4793 2 года назад
Best explaination for all the three things. It makes whole concept easy for me, easy to use now. 🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰
@hosseinpanahy5358
@hosseinpanahy5358 7 месяцев назад
awesome material,, keep the good job on
@devopsdeekay8584
@devopsdeekay8584 Год назад
Awesome explanation. Thank you very much. More subscribers!
@arpanbanejee5143
@arpanbanejee5143 2 года назад
Superb explanation, made the concepts crystal clear in such a short video! Thanks a ton!
@sumitarora6429
@sumitarora6429 2 года назад
You told everything very clearly. It helps. Thanks
@Raj00001Mr
@Raj00001Mr 2 года назад
Perfectly done. Thanks😇
@osamagamal495
@osamagamal495 2 года назад
the greates explanation ever!
@louicoder
@louicoder 2 года назад
THis was really a precise to the point video, now I can go ahead and optimize my code. thanks a lot Chaim 🎉🎉🎉🎉🎉
@magosiatanska2867
@magosiatanska2867 2 года назад
Best explanation ever :) thank you.
@blackcoffeedevelopment3522
@blackcoffeedevelopment3522 Год назад
Thank you! This was really helpful and well explained with a simple demonstration.
@kamranhamid9175
@kamranhamid9175 2 года назад
Your explanation and use cases were to the point
@subashbose2924
@subashbose2924 2 года назад
excellent explaination sir keep uploading new videos its help us
@alexandrexp985
@alexandrexp985 2 года назад
Awesome explanation, simple and straight to the point.
@omaralsadidev
@omaralsadidev Год назад
Hi Chaim, I really like your videos! It helps me a lot with advanced topics! THANK YOU MAN!
@siddheshb.kukade4685
@siddheshb.kukade4685 3 года назад
thank you sir you have cleared all my doubts
@namanagarwal4233
@namanagarwal4233 3 года назад
Got all my doubts cleared! Thanks a lot.
@vidumini23
@vidumini23 3 года назад
Woow.. Thank you.. Understood it well.
@shreejanregmi
@shreejanregmi 5 месяцев назад
Still the best video in this topic by far
@codewithedraak
@codewithedraak Год назад
i always re watch this video before my interview also suggest my friends about this video
@dannyroberts4067
@dannyroberts4067 Год назад
Good video, very concise. QQ for the useCallback, is the changeChildNumber function still needed? Can't the setChildNumber go straight into the useCallback?
@edinburghrules
@edinburghrules Год назад
Excellent explanation 🚀
@juanchibrossa8569
@juanchibrossa8569 2 года назад
Simply amazing, thanks a lot!
@CodingWithChaim
@CodingWithChaim 2 года назад
Glad you liked it!
@dhunsworth
@dhunsworth 3 года назад
Fantastic, easy to follow example! Thanks!
@rubenmartinez2807
@rubenmartinez2807 3 года назад
what great video man, I feel relieved by the amazing content here
@rasikakshirsagar5563
@rasikakshirsagar5563 2 года назад
Thank you so much for detailed information!
@SchkuenteQoostewin
@SchkuenteQoostewin 3 года назад
Memo() is a HOC that monitors useCallBack creates a "singleton pattern" of the enclosed function useMemo creates a smarter Singleton Pattern that looks at the args as well
@MrFattylee
@MrFattylee 3 года назад
Thank you. Very helpful. Subscribed!!
@iUmerFarooq
@iUmerFarooq 4 года назад
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
@CodingWithChaim
@CodingWithChaim 4 года назад
Yes absolutely! I think thats a great idea to add to the list.
@iUmerFarooq
@iUmerFarooq 4 года назад
@@CodingWithChaimYeah, Thanks for hearing me.
@pavel1429
@pavel1429 4 года назад
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)
@CodingWithChaim
@CodingWithChaim 4 года назад
Yea this is on the list! I have so much to get to thanks to all the great suggestions
@shraddhapunjabi232
@shraddhapunjabi232 2 года назад
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 :(
@iliketocode6986
@iliketocode6986 4 года назад
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
@muhammadjawadurrahim4883
@muhammadjawadurrahim4883 3 года назад
This is pure GOLD !!! Awesome content
@londzon1340
@londzon1340 4 года назад
the best explanation here in youtube
@CodingWithChaim
@CodingWithChaim 4 года назад
Thank you! I’m glad you found this helpful
@macaroni976
@macaroni976 2 года назад
very detailed explanation love your videos on react. but can you slow down a little bit.
@saisagarsharma
@saisagarsharma 2 года назад
Thanks man. it really helped. Subscribing !!
@user-lf8gj2lj2p
@user-lf8gj2lj2p 2 года назад
Great video, I am your new subscriber!
@pranavambhore9215
@pranavambhore9215 3 года назад
Nice explanation 👍🏾
@deamorta6117
@deamorta6117 3 года назад
Subscribed, really good teacher!
@CodingWithChaim
@CodingWithChaim 3 года назад
Thank you! Welcome to the channel
@waqasrana5734
@waqasrana5734 2 года назад
BEST , thank you so much
@officialabdulrehman
@officialabdulrehman 3 года назад
Crystal clear explanation ❤ Subbed
@gravelessForever
@gravelessForever 3 года назад
You sir earned a sub
@mrSargi7
@mrSargi7 Год назад
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?
@CodingWithChaim
@CodingWithChaim Год назад
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.
@r13aero
@r13aero 2 года назад
you are the best sir
@arvindvs8934
@arvindvs8934 3 года назад
You, Sir, are a wonderful man!!
@CodingWithChaim
@CodingWithChaim 3 года назад
Thank you that’s very kind
@Rolanditou
@Rolanditou 2 года назад
Shouldn't all components render with memo by default in the next React version ?
@NayTunThein
@NayTunThein 2 года назад
Explanations are superb! But, I would recommend removing background music when speaking
@the_bitcoin_guy
@the_bitcoin_guy 3 года назад
So what is the difference between useMemo and useCallback. Switching useMemo with useCallback in your example will make no difference in the behaviour. Right ?
@felipev5607
@felipev5607 2 года назад
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
@CodingWithChaim
@CodingWithChaim 2 года назад
Thank you! Yes for sure, go for it!
@hanibal43
@hanibal43 3 года назад
you are goldmine of knowldage!
@CodingWithChaim
@CodingWithChaim 3 года назад
thank you!
@MrAlithom39
@MrAlithom39 4 года назад
super helpful video, very well explained, thanks!
@CodingWithChaim
@CodingWithChaim 4 года назад
Thanks! Very glad you found it helpful
@planetmall2
@planetmall2 3 года назад
Excellent explanation thank you.
@CodingWithChaim
@CodingWithChaim 3 года назад
You’re most welcome
@georgevinueza7249
@georgevinueza7249 3 года назад
This is gold
@jeetviramgama4392
@jeetviramgama4392 Год назад
7:19 are incrementLocal and changeChildNumber gets re created every single time when App component is rendered?
@CodingWithChaim
@CodingWithChaim Год назад
yep thats exactly it
@banjotola4898
@banjotola4898 Год назад
awesome!
@pictzone
@pictzone 2 года назад
Wouldn't using useCallback instead of useMemo also work in the last example?
@adi9191ful
@adi9191ful 16 дней назад
These will not be used from react 19 onwads 🙂
@fooked1
@fooked1 3 года назад
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?
@CodingWithChaim
@CodingWithChaim 3 года назад
Exactly. UseMemo caches the value returned by the function where as useCallback caches the function itself
@paccioti
@paccioti 3 года назад
would sending setChildNumber to child break Memo same as sending changeChildNumber function?
@CodingWithChaim
@CodingWithChaim 3 года назад
Yes it would
@sudhanshuchaurasia1101
@sudhanshuchaurasia1101 2 года назад
👏👏👏👏👏
@yummysoup
@yummysoup Год назад
thank you
@guimauve_
@guimauve_ 3 года назад
Good explaination but the background music makes focussing on what you're saying harder.
@taniadelatorre2017
@taniadelatorre2017 Год назад
this is a very personal opinion: the background music distract me a lot, I prefer no music
@sarelvaroner8921
@sarelvaroner8921 3 года назад
Thanks!
@CodingWithChaim
@CodingWithChaim 3 года назад
You’re welcome!
@skewty
@skewty 3 года назад
Great video but a bit too overly contrived and obvious simplifications render the example broken. Like why create a function with signature A that calls a function with signature A? Just call the original function. The same can be said for the 1st parameter to useContext.. just pass the original function. When both simplifications / optimizations are done, the idea / example breaks.
@skewty
@skewty 3 года назад
It's almost as if Chaim doesn't realize he can pass functions as they are / fails to see the missed opportunity / optimization
@gitcat8160
@gitcat8160 3 года назад
Only added more questions than before lol
@iliketocode6986
@iliketocode6986 3 года назад
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
@ms-kb1kt
@ms-kb1kt 4 года назад
Your explanation and examples are really great to understand but please don't use background music.
Далее
React-Intl | Internationalization Basics in React
28:49
Starman🫡
00:18
Просмотров 12 млн
Mastering React Memo
26:56
Просмотров 135 тыс.
React Interview Questions 2020 (7 More Questions)
23:16
You might not need useEffect() ...
21:45
Просмотров 159 тыс.
React.memo, useMemo, and useCallback Optimizations
22:09
REAL React Interview Questions
8:08
Просмотров 190 тыс.
Never Forget React forwardRef Again
9:33
Просмотров 18 тыс.
10 React Antipatterns to Avoid - Code This, Not That!
8:55
The correct way to optimise React
11:29
Просмотров 33 тыс.