Learn React Hooks: useMemo - Simply Explained!

  Рет қаралды 120,693

Cosden Solutions

Cosden Solutions

Күн бұрын

Пікірлер: 247
@cosdensolutions
@cosdensolutions 9 ай бұрын
Hope you enjoyed the video! I also have a really cool and unique course that will teach you way more than this video. You'll learn how to build an actual complex project with React. It's called "Project React" and you can find it at cosden.solutions/project-react. Also, I have a free weekly newsletter called "Import React" with tutorials, news, and cool stuff about React! You can sign up at cosden.solutions/newsletter?s=ytc
@EnesKab
@EnesKab 8 ай бұрын
Please add also NextJS to the Project React Course 🙂
@abhishekprajapati6849
@abhishekprajapati6849 Жыл бұрын
This was my first and the last useMemo tutorial. I just loved the way you isolated the concept along with a really simple explanation. Thank you!
@mehdiSupp
@mehdiSupp 11 ай бұрын
Timing the "like and subscribe" popup exactly after you explain the solution is genius. I clicked like and it felt good I don't know why lol
@mostinho7
@mostinho7 11 ай бұрын
Done thanks clear 6:50 useMemo memoizes the result of a calculation/ function call until some dependencies change
@RichReflectionz
@RichReflectionz Жыл бұрын
As someone still new to react and web dev in general, this is awesome, the main hooks I’ve been using have been useState and useEffect. Would be great to see one about useRef too :)
@cosdensolutions
@cosdensolutions Жыл бұрын
It's coming! Just started this 😁
@amarmusovic7748
@amarmusovic7748 9 ай бұрын
This could be the best useMemo tutorial I've seen. And I've seen a lot. Almost too many. 😂 Oh, and I love that you keep rounding 29.999.999 to 29 million. Made me chuckle every time... 🤗🤗
@sahasrabhujaneuron5975
@sahasrabhujaneuron5975 Жыл бұрын
I've been struggling with this concept, but this video really made it easy and simple to understand. Many thanks!
@cosdensolutions
@cosdensolutions Жыл бұрын
glad it helped! 🤙
@areebafatima7436
@areebafatima7436 Жыл бұрын
I am so happy that I got landed to this channel. So concise, loving it.
@SWE507
@SWE507 10 ай бұрын
Im enrolled in a couple of intermediate and advanced react courses.. even bought a couple of books.. But man, your vids are waaay better and so amazing! clear and concise!!!! i wish you had a full on intermediate/advanced react course. i would gladly pay for that! Thank you so much for existing!!!
@cosdensolutions
@cosdensolutions 10 ай бұрын
I'm just about to launch a course that has 2 parts. The first part is more beginner, the second is more intermediate/advanced ☺️ if you get it when it launches you get both for the price of one
@SWE507
@SWE507 10 ай бұрын
Will be sure to do so!! thank you! :D @@cosdensolutions
@JoshuaMusau
@JoshuaMusau 19 күн бұрын
So articulate and concise. God bless you
@kacperstepien8640
@kacperstepien8640 Жыл бұрын
The best useMemo explanation I've seen.
@bhavikpatel2007dx
@bhavikpatel2007dx Ай бұрын
Perfectly explained.. Simple, Clear and Straightforward.. ThankS
@adiletbaimyrzauulu6589
@adiletbaimyrzauulu6589 Жыл бұрын
Hey, i really like your way of explaining. I bought an online course on React, but sometimes I just don't get it on the course, and your videos make it super duper clear for me. Thank you for your job, wish you all the best, and I hope some day you are going to have 500k subs on youtube.
@cosdensolutions
@cosdensolutions Жыл бұрын
thank you for the kind words! I'm also working on a course by the way, will have this teaching style and a really well thought out plan that I haven't seen done in another course before! Coming in a couple of months
@mandardeshpande7976
@mandardeshpande7976 Жыл бұрын
No one has ever articulated this topic so well. Because it's simple yet confusing. Also I was tired of watching premium full blown course about shopping cart app with tailwind and what not, all to explain the few key concepts hardly for 5 mins which eventually gets buried somewhere in the middle. Thanks for the short and sweet content.
@CalvinJKu
@CalvinJKu 3 ай бұрын
Man this video is gold! Thank you! Your useEffect video is also the best I've seen. Now I've decided that I'm gonna watch all your videos!
@Ahamedmukshithm
@Ahamedmukshithm 23 күн бұрын
bro you are a react monster
@smrpkrl
@smrpkrl Жыл бұрын
thank god i stumbled upon your channel..i am learning about all the hooks that react has to offer through your channel..i am loving the clear explanations that you provide..not a single dull moment in the video! kudos to you sir! love you!!!
@rozitahasani3307
@rozitahasani3307 4 ай бұрын
It was great. I didn't understand useMemo while I had read many articles about it but this video was very useful. now I know its logic and usage. Thank you
@erhan.emrah.fırat
@erhan.emrah.fırat Ай бұрын
Very clean explanation! Thank you!
@2029leandro
@2029leandro 10 ай бұрын
This guy is the best teaching react stuff
@robboerman9378
@robboerman9378 7 ай бұрын
After watching 3 of your videos I have learned more than reading 3 books on React. Your videos are exceptionally clear. Thanks
@shohanredwan
@shohanredwan Жыл бұрын
Wow... perfectly explained man, Thanks.
@twoatsea
@twoatsea Ай бұрын
Thank you. You are a great teacher and presenter!
@TahaAli-k6l
@TahaAli-k6l Жыл бұрын
Hi sir, I am grateful that I landed here and learn some valuable concepts of useMemo, I have a question that on 11:30 minute you added the count as a dependency array, now when a count changes that computation will run again, then how the usememo is beneficial here, let me know please?
@cosdensolutions
@cosdensolutions Жыл бұрын
The useMemo is not to prevent a re-render, but rather control when it happens. In that example we did indeed invalidate what we did by adding count, however that's necessary. Our memo depended on count so we had to provide it. The benefit lies when we add a new state variable that is not related to that, then useMemo won't re-render when that changes. So again, we're not trying to prevent a re-render, but rather control when it happens and only have it happen when absolutely necessary, otherwise return the memoed value
@pixelichi
@pixelichi 3 ай бұрын
Great tutorial! Thank you! I feel confident using useMemo now!
@srsh12345
@srsh12345 2 ай бұрын
Loving your breakdown of the react hooks. thanks for sharing
@HerlonCosta
@HerlonCosta 11 ай бұрын
It's definitely the best explanation I've ever seen. Thank you very much!
@LauraDuranVelazquez-md4ot
@LauraDuranVelazquez-md4ot 7 ай бұрын
Thank you for explaining these concepts so simply! Love your videos.
@pragatijadhav26
@pragatijadhav26 10 ай бұрын
Best explanation ever. understand in one go.
@Ksahdia
@Ksahdia Жыл бұрын
Thank you very much for the easier explained concepts. I'm watching your videos to understand my lessons better. Both compliment each other well.
@cosdensolutions
@cosdensolutions Жыл бұрын
wonderful!
@badenis1291
@badenis1291 11 ай бұрын
Made me rethink the way I was seeing this hook. Thanks
@urprakashgupta
@urprakashgupta 2 ай бұрын
Finally understand this hook after lot of stuggle !!
@fizdanielz
@fizdanielz Жыл бұрын
You have the best tutorials channel 🙌🙌🙌🙌
@hoangtran-ek8mn
@hoangtran-ek8mn Жыл бұрын
Ohhh mannn. Why are you so good at teaching? Thank you so much!!!
@cosdensolutions
@cosdensolutions Жыл бұрын
You're most welcome ☺️
@uquantum
@uquantum Жыл бұрын
Really useful tutorial. Thanks for being so helpful!
@AnnaHuang-v9i
@AnnaHuang-v9i 10 ай бұрын
the best video explains useMemo!! thank you so much!
@AsmaaRefaat-h8c
@AsmaaRefaat-h8c 10 ай бұрын
you are THE BEST to explain!
@harshitkrvishwakarma3602
@harshitkrvishwakarma3602 Жыл бұрын
Love your explanations, you have made react a lot simpler.
@rood4449
@rood4449 Жыл бұрын
that is the perfect fundamentals . it was very efficient to understand the how important useMemo . thx :)
@cosdensolutions
@cosdensolutions Жыл бұрын
Glad you found it useful! 🤙
@wow-edu-and-dev
@wow-edu-and-dev 2 ай бұрын
Great explanation! Thank you
@bittukumar-oc1vv
@bittukumar-oc1vv 3 ай бұрын
Thank you so much for this lecture.
@netaivgi
@netaivgi 7 ай бұрын
So simply explained! wow, amazing
@jaykaytech
@jaykaytech 11 ай бұрын
the most clear explanation!
@DarkRider213
@DarkRider213 11 ай бұрын
this was a perfect explanation - thank you!
@coolme7437
@coolme7437 Жыл бұрын
Best tutorial for useMemo!
@AbsolutePain
@AbsolutePain 11 ай бұрын
Hey cosden, we can achieve the similar results using useEffect ? so how do we identify when should we use memo ? // Use effect equivalent: import { useState, useMemo, useEffect } from "react"; import { data } from "./utils/data"; const Counter = () => { const [arr] = useState(data); const [selectedValue, setSelectedValue] = useState(0); useEffect(() => { const val = arr.find((elem) => elem.isSelected); setSelectedValue(val); }, [arr]); const [count, setCount] = useState(0); return ( Count:{count} setCount(count + 1)}>+1 selectedValue : {selectedValue.id} ); }; export default Counter; Thnaks for the video. Can you make a complete project in react with best practices. Thanks.
@cosdensolutions
@cosdensolutions 11 ай бұрын
So while your example works, it's not the recommended approach. The way you have it, you have an extra state variable that you have to manage and a whole useEffect to manage it. If you do it like I showed in useMemo, then selectedValue automatically gets re-computed when the array changes, and you don't have to do it yourself. That's why it's a better approach. There are a lot of times where something shouldn't be done with an useEffect even if it can, just because it introduces an extra dependency you have to manage and keep up to date. Also, your example creates an extra render cycle in the component which is unnecessary
@jitujahagirdar613
@jitujahagirdar613 11 ай бұрын
Thanks for this video 👍👍👍 really good way that you explain . I am lazy person who understand only if simplify way to explain of context and you did it 😜🤗. Good job..!😊
@allan_gr
@allan_gr Жыл бұрын
Simply explained indeed, Thank you.
@PriyaToliwal
@PriyaToliwal Жыл бұрын
Hi, your way of teaching is very easy to understand and helps me learn more concepts. Please make a video on Reactjs Forms as well.. it would really help me understand forms better. Thanks for making learning so easy and effective.
@harag9
@harag9 Жыл бұрын
Great video, thanks for this, I'll have to look at implementing this now.
@rimkaaf5697
@rimkaaf5697 4 ай бұрын
Very good explanation 👍🏽
@ShannonSimonCherry-b7t
@ShannonSimonCherry-b7t Жыл бұрын
So good! You explained it perfectly!
@mDHARYL
@mDHARYL 7 күн бұрын
very good explanation :D
@ozzzpo
@ozzzpo Жыл бұрын
dude you're awesome. Thank you so much for your explanations, now I guess I don't need to watch other videos about react hooks :)
@cosdensolutions
@cosdensolutions Жыл бұрын
☺️
@dharylovey
@dharylovey 11 ай бұрын
I like your tutorial very short and will explain. Thank you so much 😊😊
@isaac-9185
@isaac-9185 Жыл бұрын
Really well explained, thank you. Also mind dropping a list of most common cases that you would use useMemo for?
@cosdensolutions
@cosdensolutions Жыл бұрын
I would only use it when there's an expensive computation to make, or when I want to prevent this from causing a expensive child component to re-render
@pcnerd5994
@pcnerd5994 Ай бұрын
Thanks, this is very helpful!
@codetechpro
@codetechpro 8 ай бұрын
that was very helpful, thank you for clearing the confusion
@WaseemAhmad-mf3wh
@WaseemAhmad-mf3wh 10 ай бұрын
Thank you for your clear explanation ❤
@dianprogrammer
@dianprogrammer Жыл бұрын
Great video I just begin my react js journey and can easily understand the concept
@reactdev2838
@reactdev2838 Жыл бұрын
Once again great tutorial...
@yaro_05
@yaro_05 5 ай бұрын
Nice tutorial, thanks!
@dstrader7583
@dstrader7583 Жыл бұрын
Thanks, Alot Man. Glad i picked your video first now i don't need to watch another video on this.
@cosdensolutions
@cosdensolutions Жыл бұрын
🤙
@athmaram4256
@athmaram4256 Жыл бұрын
Great explication bro. Thank you very much
@gionniilbassotto
@gionniilbassotto 11 ай бұрын
so useMemo is fairly similar to useEffect? but useEffect is called when the page is loaded and/or for some dependencies?
@acm.marques
@acm.marques 3 ай бұрын
great!! video man
@Viva-07
@Viva-07 11 ай бұрын
Awesome...very well explained
@2ameridiem
@2ameridiem 8 ай бұрын
What is the difference between useMemo and useEffect? If we wrap the selectedItem function inside a useEffect like- useEffect( ( )=>{ const selectedItem=items.find((item)=>item.isSelected) },[items ] ) then it's serving the same purpose.
@abhinavdhama3014
@abhinavdhama3014 Жыл бұрын
Amazing amazing amazing explanation bro . ♥️♥️♥️♥️♥️. Plss do a javascript series also
@martrom0
@martrom0 9 ай бұрын
Wonderful !! 👏 I subscribe right away !
@mathemagicstelugu7848
@mathemagicstelugu7848 Жыл бұрын
Really its a Last Usememo video for me🥰🥰🥰
@MuhammadRidwan-kq4yw
@MuhammadRidwan-kq4yw 6 ай бұрын
youre an react angel haha,awesome bro,thank you
@Vishal360
@Vishal360 11 ай бұрын
every tutorial of cosden solution is last tutorial ur gonna watch - Fr ✌✌
@varnerdamasceno8093
@varnerdamasceno8093 7 ай бұрын
This video helped me a lot.
@AkashYadav-di6kd
@AkashYadav-di6kd 8 күн бұрын
Thank you very much, sir.
@TusharBachchan
@TusharBachchan 8 ай бұрын
Great explanation!
@RickCodez
@RickCodez Жыл бұрын
Very well explained!
@BBocho
@BBocho Жыл бұрын
great explanation, thank you very much!
@nawazishali274
@nawazishali274 Жыл бұрын
Ohh man nicely explained 🎉❤
@agosolsgaming4036
@agosolsgaming4036 10 ай бұрын
awesome explanation, thanks
@Onto.walking
@Onto.walking 4 ай бұрын
Premium explanation
@AyushGupta-kp9xf
@AyushGupta-kp9xf 8 ай бұрын
Nice explanation, appreciate that. Btw dude how do you spam that fast!
@ihortrofymov4097
@ihortrofymov4097 2 ай бұрын
do you still need useMemo for the case with === count? what is the sense of useMemo in this case if selectedItem should be recalculated when you click the button? prevent recalculation when page is rerendered, but items and count are same?
@flux2956
@flux2956 4 ай бұрын
For all the new react developers watchng this video, you wont need usememo, usecallback, and memo hooks again. React now has it's own compiler which will do this for you automatically.
@cosdensolutions
@cosdensolutions 4 ай бұрын
yes but good luck finding a job where they use cutting edge React. Even after 19 useMemo will still be important. It'll be a while before it truly goes away
@bhargavchadalla
@bhargavchadalla Жыл бұрын
Thank you, great explanation
@uzairahmed2975
@uzairahmed2975 10 ай бұрын
Love it the way you explained everything single detail, Can I also use useMemo with autocomplete with fetch?
@cosdensolutions
@cosdensolutions 10 ай бұрын
yeah you can!
@ProfessorRagna
@ProfessorRagna 23 күн бұрын
How can we realize potential performance optimizations not just from a noticeable UI issue, but from the browser or React DevTools? Would love a similar video to this that discusses seeing the issue in the devtools and fixing it afterwards in order for us to understand how to properly debug performance issues like this.
@prasannagramopadhye4506
@prasannagramopadhye4506 Жыл бұрын
Great Explanation, thank you. I have 1 doubt. If I use useState to store the value of selected items and changed its value only when there is change in the dependency array of the useEffect hook, then will it produce the same result? If yes then what is the difference between the two ? function Demo({}: DemoProps) { const [count, setCount] = useState(0); const [selectedItem, setSelectedItem] = useState(0); const [items] = useState(initialItems); useEffect(() => { const temp = items.find((item) => item.id === count) setSelectedItem(temp) }, [items]) return ( Count: {count} Selected Item: {selectedItem?.id} setCount(count + 1)}> Increment ); }
@cosdensolutions
@cosdensolutions Жыл бұрын
So first of all in your example you're missing `count` in your dependency array. You want that useEffect to run as count changes, as well as when items changes. Second of all, that code is equivalent, but now you have an extra piece of state + the hook that keeps it in sync. The way I showed in the video is better because the "sync" happens automatically. That approach is better because it has less code (one less hook) and less responsibility (selectedItem is auto updated through `useMemo` without manually having to do anything) So you're basically doing the same work, just with extra dependencies, which isn't ideal 😁 best to keep things simple and automatic
@sweekiatwong8995
@sweekiatwong8995 Жыл бұрын
was thinking the same thing glad to have found this exchange in the comments
@bbbeo8912
@bbbeo8912 Жыл бұрын
Thank you both for asking and answer. I'm about to ask the same but got the point here.
@oscardasilva971
@oscardasilva971 Жыл бұрын
Well explained Thank you very much.
@khalidamerica1848
@khalidamerica1848 3 ай бұрын
I'm new to React and i'm asking if we could solve this probleme using useEffect Hook , by passing the "items" in the dependency Array ?
@kanieseiya4134
@kanieseiya4134 3 ай бұрын
Nope
@kanieseiya4134
@kanieseiya4134 3 ай бұрын
Use effect will compute the value again where as use Memo returns the computed value
@khalidamerica1848
@khalidamerica1848 3 ай бұрын
​@@kanieseiya4134 i dont get it ?? UseEffect is also will run first when the comp in intialzed and only if "items" array changed ??
@cordial
@cordial Жыл бұрын
But when you add count to the use memo dependency array, are you not now doing the find again on every click? Oh I guess this isn't a long running task now as its not searching through the whole array any more. But, doesn't that negate the reason to add useMemo in the first place?
@cosdensolutions
@cosdensolutions Жыл бұрын
Yep it does, but that's what you want. You don't want to prevent a re-compute, but rather control when it happens. You need the count to perform that operation so there's no way around it. However if you added a new state variable and changed that, then it wouldn't re-compute. It would without useMemo. That's the goal, to control and only when needed re-calculate!
@dharmeshgohil9375
@dharmeshgohil9375 Жыл бұрын
all your video is awesome keep it up ,make small project which make use of the all hooks how to use in company level or share some difficult situation of it when to use which hooks use it will be great help
@cosdensolutions
@cosdensolutions Жыл бұрын
Currently in the process of making a full on course with exactly that!
@gharbos
@gharbos Жыл бұрын
Appreciate your explanation ! thanx
@dariotizzoni1517
@dariotizzoni1517 Жыл бұрын
Hi, I’m new to react and your videos are really helpful. I have two questions: 1. In the last specific scenario, is it really necessary using useMemo? I mean, the only cause of rerender is when count changes, so useMemo would compare every render the dependecies. 2. What is the differences between useMemo and useCallback?
@cosdensolutions
@cosdensolutions Жыл бұрын
1. In the context of the video, no it isn't. But the goal was to show you how it works! 2. useMemo returns a value, useCallback returns a function. They are the same otherwise!
@dariotizzoni1517
@dariotizzoni1517 Жыл бұрын
Oh, that’s right! Really thanks 😊
@rakotonanaharytsantahavana4825
@rakotonanaharytsantahavana4825 6 ай бұрын
Really great video. I have few questions if u don't mind. What are the differences between useMemo and useEffect ? Not talking about syntax or the option return function. Instead of using useMemo in this case, you can use useEffect and put items as dependencies. useEffect(()=> {selectedItems = item.find(item=> item.id)}, [items]}) Re-computation only triggered once items is changed, and instance is destroyed to create a new one right? Same as useMemo? So why useMemo instead of useEffect? Is it linked to memory usage or am i missing something? Thank you
@jackmackenzie8466
@jackmackenzie8466 7 ай бұрын
Great videos. 1 question though, when you have count and items in the hook, why doesn't that lag as it seems like the items are being looped each time count changes?
@MrAnofor
@MrAnofor Жыл бұрын
doesn't adding 'count' as a dependency recalculates selectedItem on every click on increment ? thus you still have the problem if you spam increment ?
@cosdensolutions
@cosdensolutions Жыл бұрын
Yes it does. The goal isn't to make things never change, but rather control when they change and prevent unnecessarily changing. Of course this code here is slow by default, I did that to show you useCallback and how it works. In this case, if you have to use count and that causes a problem, then maybe it's time to rethink the component and move some things around to avoid that
@saadchraibi6712
@saadchraibi6712 Жыл бұрын
You can use an object or a Map for items where the keys are the ids. This would allow you to look up items in constant time (O(1)) by simply accessing the item via its id.
@kizigamer6895
@kizigamer6895 Жыл бұрын
@@saadchraibi6712 explain what you are saying pls more in detail with example that could be helpful why would using key be helpful here?/
@TorreLoCascio-mq1bx
@TorreLoCascio-mq1bx 8 ай бұрын
How does React know if "items' changes with looping through all 29mil items? Wouldn't that be the same performance issue we had? Thanks, great tutorial in general.
@gnsc
@gnsc 6 ай бұрын
Nice explanation
@redhood7105
@redhood7105 8 ай бұрын
God tier video
Learn React Hooks: useCallback - Simply Explained!
17:15
Cosden Solutions
Рет қаралды 112 М.
Learn React Hooks: useRef - Simply Explained!
12:42
Cosden Solutions
Рет қаралды 119 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
You Probably Shouldn't Use React.memo()
10:17
Theo - t3․gg
Рет қаралды 58 М.
Mastering React Memo
26:56
Jack Herrington
Рет қаралды 138 М.
Learn React Hooks: useContext - Simply Explained!
15:46
Cosden Solutions
Рет қаралды 198 М.
Design patterns in React
14:37
Cosden Solutions
Рет қаралды 182 М.
The Biggest Mistake Intermediate React Developers Make
18:32
Cosden Solutions
Рет қаралды 36 М.
Learn React Hooks: useEffect - Simply Explained!
14:07
Cosden Solutions
Рет қаралды 179 М.
All React Hooks Explained - React Hooks Tutorial 2025
1:28:44
PedroTech
Рет қаралды 12 М.
7 React Lessons I Wish I Knew Earlier
7:30
Code Bootcamp
Рет қаралды 74 М.
Learn React Hooks: useReducer - Simply Explained!
13:48
Cosden Solutions
Рет қаралды 72 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 495 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН