React.memo, useMemo, and useCallback Optimizations

  Рет қаралды 44,695

Code Bushi

Code Bushi

Күн бұрын

Learn how to optimize React Components using React.memo, useMemo, and useCallback hooks.
Key Takeaways!
4:40 - When a Parent Component re-renders, all Child components will re-render as well.
5:30 - React.memo is a higher order component, used with functional components. React.memo will compare the previous props to the next props, and if different, will re-render the component.
6:52 - JavaScript Primitives (string, number, boolean) being passed as a prop will work fine with React.memo.
7:30 - Arrays, Objects, Functions being passed as a prop will not work with React.memo alone. You'll need to use hooks like useMemo around the Array or Object.
8:17 - In a functional component, every re-render will cause everything in the function body to be "re-created". So Arrays, Objects, and Functions will be new and different on every re-render. When these are passes to the Child Component, it will cause the Child to re-render.
8:55 - Wrapping Arrays and Objects with the useMemo hook will solve this problem. Better yet, if the dependency array is empty, you should just hoist it out of the function body.
14:24 - When passing Functions down as props, and when Functions are used in a dependency array, wrap them in the useCallback hook to avoid re-renders and prevent useEffects from firing on each re-render.
20:30 - Don't just memoize all the things. Here is the blog post by Kent about when you should use these memoization techniques: kentcdodds.com/blog/usememo-a...
Finished Code: github.com/codebushi/react-memo
Follow me on
Twitter: / huntarosan
Dev.to: dev.to/changoman

Пікірлер: 85
@tlibby730
@tlibby730 4 жыл бұрын
I've searched far and wide for a simple explanation of these hooks. Thank you very much for posting this.
@codebushi
@codebushi 4 жыл бұрын
Thanks for watching!
@archerkayson7892
@archerkayson7892 2 жыл бұрын
Sorry to be so offtopic but does anybody know a tool to log back into an instagram account? I somehow forgot the account password. I appreciate any tricks you can offer me.
@laurenznitert2623
@laurenznitert2623 4 жыл бұрын
You gotta hit that clicky clicky clicky
@wasuuu
@wasuuu 4 жыл бұрын
One of the great tutorials available on KZfaq. Thanks!
@mr.anonymous6871
@mr.anonymous6871 3 жыл бұрын
I have never seen such a simple explanation of memo and useMemo. It's great :):):)
@viseja1423
@viseja1423 3 жыл бұрын
Thank you. It's one of the most simplified stunning demonstration I have ever seen. Keep going!! :)
@PublicUser2000
@PublicUser2000 2 жыл бұрын
The best video I have seen so far on these hooks. Thanks !
@jaequery1112
@jaequery1112 3 жыл бұрын
I listened to this without video no less (while riding a bike) and even then it helped me to clear up the confusion, thanks!
@collocheru
@collocheru 3 жыл бұрын
This is the explanations I needed, really good 🙏
@therealdrecu
@therealdrecu 4 жыл бұрын
I didn't expect you to explain so in detail and comprehensible on how to use the callbacks. I definitely learned one or two things and I best start now tinkering on my code. Thanks and keep content like this coming, subbed!
@codebushi
@codebushi 4 жыл бұрын
Thank you!
@ofiry
@ofiry 3 жыл бұрын
Awesome video man, I really like your key takeaways on the description, u should do more videos like this!
@brandonb478
@brandonb478 3 жыл бұрын
This is a great video explaining everything. Super clear and super concise.
@dangre00
@dangre00 3 жыл бұрын
Great video and explanation! I'm baffled why there's such a shortage of direct and easy to understand tutorials.
@ianaustria8868
@ianaustria8868 4 жыл бұрын
I've been reading some tutorials about these topics but i still was confused. Watching this vid eliminated all my confusion. Thanks a lot.
@TrainExplore
@TrainExplore 3 жыл бұрын
After exploring 100 of videos Bang, this one is the explanation
@MrCristianfavaro
@MrCristianfavaro 3 жыл бұрын
Really great examples. And he is also using fetch to provide extra info about the topic. Congrats. Thanks a lot.
@rakshitlakhatariya137
@rakshitlakhatariya137 Жыл бұрын
Best explanation on these topics so far Thank you so much.
@DennisCastroAlonzo
@DennisCastroAlonzo 4 жыл бұрын
Hey, thanks for the video, reading the blogpost also helped to understand better the topic (optimizations - pros and cons)
@dytra_io
@dytra_io 3 жыл бұрын
finally i know how all of them works,thankyou so much, you're my hero! subscribed!
@Jmacro
@Jmacro 4 жыл бұрын
awesome tutorial! explained clearly and straight to the point :)
@andregomes7232
@andregomes7232 2 жыл бұрын
Amazing video ! Its awesome how you can simplify things to explain man, keep it up. cogratulations
@rohit87
@rohit87 4 жыл бұрын
Very well explained! Thank you so much!!!! more on react hooks specially API Calls with All kind of request in one custom hook
@andersonanjos2811
@andersonanjos2811 4 жыл бұрын
Clear like water. Thanks to explain.
@netuse4956
@netuse4956 2 жыл бұрын
excellent demonstration of hooks, better then rest
@codingcage5906
@codingcage5906 2 жыл бұрын
Simple an to the point , cleared every doubt
@gauravpoudel7288
@gauravpoudel7288 4 жыл бұрын
the best explanation on these topics. great!
@alexanderpetkov7634
@alexanderpetkov7634 4 жыл бұрын
Awesome video, man! Thanks for sharing!
@rocmarkz6742
@rocmarkz6742 4 жыл бұрын
thanks very clear and easy to understand. keep up the work !!
@alexispell4251
@alexispell4251 3 жыл бұрын
Very useful video... thanks a lot, man!
@limitless9483
@limitless9483 3 жыл бұрын
Straight to the point, thank you!
@user-px3gx5zi6l
@user-px3gx5zi6l 3 жыл бұрын
Very very helpful explanations..!! Thank you so much
@lucienchu9649
@lucienchu9649 4 жыл бұрын
Pretty simple & straightforwards explanation. Now I am working on how to use them along with the Context api. Using that one these days and found it is awesome. However, I also found that I am kind of exploiting it and start making my stuff messy.
@NomaanulHasan
@NomaanulHasan Жыл бұрын
Thank you very much for this video, you explained it very well and it helped me a lot.
@brinthkr1533
@brinthkr1533 3 жыл бұрын
Excellent explanation !!!
@MateenKadwaikar
@MateenKadwaikar 3 жыл бұрын
Thanks, man for such an informative video.
@arijitpatra
@arijitpatra Жыл бұрын
Best explanation of this topic.
@prnk139
@prnk139 2 жыл бұрын
Great Explanation !
@chamnil8666
@chamnil8666 3 жыл бұрын
Thank you sooo much,for the clear explanation.
@FellipeSNC
@FellipeSNC 3 жыл бұрын
Amazing explanation!
@VigneshwaranChandrasekaranA
@VigneshwaranChandrasekaranA 4 жыл бұрын
Thanks for solved my long time problem. 🙏🏽👍🏻🤝👌🏼
@anuuoerif4339
@anuuoerif4339 4 жыл бұрын
it is wonderful tutorial, thanks for explaining it very welll
@NathanHughFoster
@NathanHughFoster 3 жыл бұрын
Great video. I think one thing you can expand on is the difference between reference and value. React.memo, useCallback, and useMemo compare preference references in memory not values. So the reason why the array prop was causing a rerender on the child is because the arrays reference (memory address) changed everytime the parent rerendered.
@paulopontovaz
@paulopontovaz 3 жыл бұрын
Nice point there. Now I'm wondering why, in terms or reference, the child doesn't rerender for the static text. Doesn't it also get stored somewhere in memory? Under the hood.
@yashmundra8497
@yashmundra8497 8 ай бұрын
@@paulopontovaz For primitive types only the values are compared and for the non primitives, the references are checked. This is known as shallow comparison. React uses Object.is() under the hood
@rickyalmeida
@rickyalmeida 4 жыл бұрын
Great tutorial, thanks! ⚛️
@bipinmsit7380
@bipinmsit7380 2 жыл бұрын
Great explanation!
@thecoder1631
@thecoder1631 11 ай бұрын
this was amazing, thank you !
@codebushi
@codebushi 10 ай бұрын
Glad you enjoyed it!
@kokoyroy
@kokoyroy 2 жыл бұрын
You are awesome dude! Thank u so much!
@eshwarenmanoharen870
@eshwarenmanoharen870 4 жыл бұрын
Great tutorial!
@yogsharma7807
@yogsharma7807 3 жыл бұрын
Is this a video or a butter so smooth to understand. Good Luck Bro.
@rajashekarpilli3132
@rajashekarpilli3132 3 жыл бұрын
Tq for the explanation, very helpful
@nofacedude9959
@nofacedude9959 4 жыл бұрын
great video, thanks man
@aykulisha
@aykulisha 4 жыл бұрын
Very helpfull! Thank you!
@MrTalmashiah
@MrTalmashiah 3 жыл бұрын
"and I'm gonna put this in a paragraph taggggggg" 6:40 You are Awesome THANK YOU
@BobbyBundlez
@BobbyBundlez 3 жыл бұрын
why is that awesome lol.. is that really funny to u ? wow so boring
@7kitt772
@7kitt772 3 жыл бұрын
thanks! now it's clear
@muchamaddestafadilah
@muchamaddestafadilah 3 жыл бұрын
Thanks, i follow your explaine vidio, with time tracker ... nice i will subscribe.
@codebushi
@codebushi 3 жыл бұрын
Thank you!
@naynyamish270
@naynyamish270 4 жыл бұрын
This is what a tutorial should look like , no need to write complicated code to explain an api or hooks in this case .
@maciekdzikdrums
@maciekdzikdrums 4 жыл бұрын
The best!
@DuyTran-ss4lu
@DuyTran-ss4lu 3 жыл бұрын
freaking awsome
@Yuri-dk9nv
@Yuri-dk9nv 3 жыл бұрын
I've understand all stuff in this video, hovewer I" m not so good in engliish. Thanx a lot! You should made more React videos/ please
@bogdangorgadze5293
@bogdangorgadze5293 4 жыл бұрын
Thank you
@anarchism_in
@anarchism_in 2 жыл бұрын
perfect
@raypenha2572
@raypenha2572 Жыл бұрын
Great
@kumarin2009
@kumarin2009 4 жыл бұрын
👌👌
@beau6077
@beau6077 4 жыл бұрын
very nice! can you do one with animated transitions between pages? That would be amazing. Thank you!
@rme1383
@rme1383 4 жыл бұрын
put the animation on the routs
@sarangsowmya9854
@sarangsowmya9854 2 жыл бұрын
In your example - what happens if you simply move the function ( fetchData ) outside of the function component App - would that be better / worse than using a useCallback ?
@gian5138
@gian5138 3 жыл бұрын
Im laughing the way he talks but the thing is he can educate us pretty well
@silvanadonato7869
@silvanadonato7869 2 жыл бұрын
useEffect and its dependencies... 🤔 not too clear, I thought that the array of useEffect had something to do with component update.
@varuncharan9109
@varuncharan9109 2 жыл бұрын
React.memo stops rendering the component repeatedly or unwantedly Use Memo cached its return values never re-render until and unless there is change in it's dependency value Use Callback also similar like use Memo but it cached the function itself I am i correct mates ?
@vetal3513
@vetal3513 3 жыл бұрын
so, the useMemo hook hasn't any profit with the simple types variables as string, number, boolean?
@zlackbiro
@zlackbiro 4 жыл бұрын
LoL, when you prevented RE_RENDER child Component by wrapping export child in useMemo, i lough so loud how simple wast that comparing from other tutorials online... :D Hahahaha
@zxginay3962
@zxginay3962 3 жыл бұрын
it basically starts at around 5:00
@limitless9483
@limitless9483 3 жыл бұрын
8:40 Referential equality
@batuhansahan
@batuhansahan 3 жыл бұрын
Why didn't you used array within useState
@elenaconn6412
@elenaconn6412 3 жыл бұрын
"When I hit the clicky.. clicky clicky..."
@NITESHSINGHNRS
@NITESHSINGHNRS 4 жыл бұрын
please remove mic from keyboard.......its itterate ....but good explained.
@Jitendra0712
@Jitendra0712 Жыл бұрын
Hi
@user-vn2nx1yq9e
@user-vn2nx1yq9e 3 жыл бұрын
не пей пиво перед записью
@okbrk
@okbrk 3 жыл бұрын
Slowest typo skills I've ever seen but good tutorial though
Learn React Hooks: useCallback - Simply Explained!
17:15
Cosden Solutions
Рет қаралды 75 М.
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 140 МЛН
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
Гараж 54
Рет қаралды 10 МЛН
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 89 МЛН
React Hook useRef and forwarding refs with forwardRef
14:46
techsith
Рет қаралды 80 М.
REACT MEMO vs USECALLBACK vs USEMEMO
13:18
Coding With Chaim
Рет қаралды 54 М.
Optimize Your React App with useMemo | React Hooks
17:26
Sofia Goyal
Рет қаралды 5 М.
Async React Hooks
25:36
Harry Wolff
Рет қаралды 50 М.
Gatsby.js with Tailwind CSS and PurgeCSS
23:15
Code Bushi
Рет қаралды 8 М.
Learn useMemo In 10 Minutes
10:42
Web Dev Simplified
Рет қаралды 467 М.
Intro to React's useReducer Hook
35:47
Code Bushi
Рет қаралды 1,3 М.
React Hooks: Advanced Hooks
20:52
Harry Wolff
Рет қаралды 87 М.
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 140 МЛН