React.memo, useMemo, and useCallback Optimizations

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • 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

Komentáře • 85

  • @codingcage5906
    @codingcage5906 Před 3 lety

    Simple an to the point , cleared every doubt

  • @TrainExplore
    @TrainExplore Před 3 lety

    After exploring 100 of videos
    Bang, this one is the explanation

  • @rakshitlakhatariya137

    Best explanation on these topics so far
    Thank you so much.

  • @tlibby730
    @tlibby730 Před 4 lety +13

    I've searched far and wide for a simple explanation of these hooks. Thank you very much for posting this.

    • @codebushi
      @codebushi  Před 4 lety +2

      Thanks for watching!

    • @archerkayson7892
      @archerkayson7892 Před 2 lety

      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.

  • @netuse4956
    @netuse4956 Před 2 lety

    excellent demonstration of hooks, better then rest

  • @arijitpatra
    @arijitpatra Před rokem

    Best explanation of this topic.

  • @mr.anonymous6871
    @mr.anonymous6871 Před 3 lety +1

    I have never seen such a simple explanation of memo and useMemo. It's great :):):)

  • @laurenznitert2623
    @laurenznitert2623 Před 4 lety +22

    You gotta hit that clicky clicky clicky

  • @dangre00
    @dangre00 Před 3 lety

    Great video and explanation! I'm baffled why there's such a shortage of direct and easy to understand tutorials.

  • @ianaustria8868
    @ianaustria8868 Před 4 lety +1

    I've been reading some tutorials about these topics but i still was confused. Watching this vid eliminated all my confusion. Thanks a lot.

  • @user-px3gx5zi6l
    @user-px3gx5zi6l Před 3 lety

    Very very helpful explanations..!! Thank you so much

  • @therealdrecu
    @therealdrecu Před 4 lety +1

    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!

  • @MrCristianfavaro
    @MrCristianfavaro Před 4 lety

    Really great examples. And he is also using fetch to provide extra info about the topic. Congrats. Thanks a lot.

  • @andersonanjos2811
    @andersonanjos2811 Před 4 lety +1

    Clear like water. Thanks to explain.

  • @jaequery1112
    @jaequery1112 Před 3 lety

    I listened to this without video no less (while riding a bike) and even then it helped me to clear up the confusion, thanks!

  • @wasuuu
    @wasuuu Před 4 lety

    One of the great tutorials available on CZcams. Thanks!

  • @brinthkr1533
    @brinthkr1533 Před 3 lety

    Excellent explanation !!!

  • @PublicUser2000
    @PublicUser2000 Před 3 lety

    The best video I have seen so far on these hooks. Thanks !

  • @DennisCastroAlonzo
    @DennisCastroAlonzo Před 4 lety +1

    Hey, thanks for the video, reading the blogpost also helped to understand better the topic (optimizations - pros and cons)

  • @NomaanulHasan
    @NomaanulHasan Před 2 lety

    Thank you very much for this video, you explained it very well and it helped me a lot.

  • @alexispell4251
    @alexispell4251 Před 3 lety

    Very useful video... thanks a lot, man!

  • @ofiry
    @ofiry Před 3 lety

    Awesome video man, I really like your key takeaways on the description, u should do more videos like this!

  • @collocheru
    @collocheru Před 3 lety +6

    This is the explanations I needed, really good 🙏

  • @NathanHughFoster
    @NathanHughFoster Před 3 lety +5

    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 Před 3 lety

      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 Před 9 měsíci +1

      @@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

  • @rohit87
    @rohit87 Před 4 lety +1

    Very well explained! Thank you so much!!!! more on react hooks specially API Calls with All kind of request in one custom hook

  • @FellipeSNC
    @FellipeSNC Před 3 lety

    Amazing explanation!

  • @viseja1423
    @viseja1423 Před 3 lety

    Thank you. It's one of the most simplified stunning demonstration I have ever seen. Keep going!! :)

  • @thecoder1631
    @thecoder1631 Před 11 měsíci +1

    this was amazing, thank you !

  • @brandonb478
    @brandonb478 Před 3 lety

    This is a great video explaining everything. Super clear and super concise.

  • @gauravpoudel7288
    @gauravpoudel7288 Před 4 lety

    the best explanation on these topics. great!

  • @limitless9483
    @limitless9483 Před 3 lety

    Straight to the point, thank you!

  • @yogsharma7807
    @yogsharma7807 Před 3 lety

    Is this a video or a butter so smooth to understand.
    Good Luck Bro.

  • @Jmacro
    @Jmacro Před 4 lety +1

    awesome tutorial! explained clearly and straight to the point :)

  • @prnk139
    @prnk139 Před 3 lety

    Great Explanation !

  • @dytra_io
    @dytra_io Před 3 lety

    finally i know how all of them works,thankyou so much, you're my hero!
    subscribed!

  • @alexanderpetkov7634
    @alexanderpetkov7634 Před 4 lety

    Awesome video, man! Thanks for sharing!

  • @lucienchu9649
    @lucienchu9649 Před 4 lety

    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.

  • @andregomes7232
    @andregomes7232 Před 3 lety

    Amazing video ! Its awesome how you can simplify things to explain man, keep it up. cogratulations

  • @rocmarkz6742
    @rocmarkz6742 Před 4 lety

    thanks very clear and easy to understand. keep up the work !!

  • @bipinmsit7380
    @bipinmsit7380 Před 3 lety

    Great explanation!

  • @chamnil8666
    @chamnil8666 Před 3 lety

    Thank you sooo much,for the clear explanation.

  • @MateenKadwaikar
    @MateenKadwaikar Před 3 lety

    Thanks, man for such an informative video.

  • @VigneshwaranChandrasekaranA

    Thanks for solved my long time problem. 🙏🏽👍🏻🤝👌🏼

  • @kokoyroy
    @kokoyroy Před 2 lety

    You are awesome dude! Thank u so much!

  • @rajashekarpilli3132
    @rajashekarpilli3132 Před 3 lety

    Tq for the explanation, very helpful

  • @muchamaddestafadilah
    @muchamaddestafadilah Před 4 lety +1

    Thanks, i follow your explaine vidio, with time tracker ... nice i will subscribe.

  • @rickyalmeida
    @rickyalmeida Před 4 lety

    Great tutorial, thanks! ⚛️

  • @anuuoerif4339
    @anuuoerif4339 Před 4 lety +2

    it is wonderful tutorial, thanks for explaining it very welll

  • @naynyamish270
    @naynyamish270 Před 4 lety +4

    This is what a tutorial should look like , no need to write complicated code to explain an api or hooks in this case .

  • @7kitt772
    @7kitt772 Před 3 lety

    thanks! now it's clear

  • @MrTalmashiah
    @MrTalmashiah Před 3 lety

    "and I'm gonna put this in a paragraph taggggggg" 6:40
    You are Awesome THANK YOU

    • @BobbyBundlez
      @BobbyBundlez Před 3 lety

      why is that awesome lol.. is that really funny to u ? wow so boring

  • @eshwarenmanoharen870
    @eshwarenmanoharen870 Před 4 lety

    Great tutorial!

  • @nofacedude9959
    @nofacedude9959 Před 4 lety

    great video, thanks man

  • @aykulisha
    @aykulisha Před 4 lety

    Very helpfull! Thank you!

  • @bogdangorgadze5293
    @bogdangorgadze5293 Před 4 lety

    Thank you

  • @DuyTran-ss4lu
    @DuyTran-ss4lu Před 3 lety

    freaking awsome

  • @maciekdzikdrums
    @maciekdzikdrums Před 4 lety

    The best!

  • @Yuri-dk9nv
    @Yuri-dk9nv Před 4 lety

    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

  • @gian5138
    @gian5138 Před 3 lety

    Im laughing the way he talks but the thing is he can educate us pretty well

  • @anarchism_in
    @anarchism_in Před 2 lety

    perfect

  • @kumarin2009
    @kumarin2009 Před 4 lety

    👌👌

  • @raypenha2572
    @raypenha2572 Před rokem

    Great

  • @beau6077
    @beau6077 Před 4 lety +1

    very nice! can you do one with animated transitions between pages? That would be amazing. Thank you!

    • @rme1383
      @rme1383 Před 4 lety

      put the animation on the routs

  • @sarangsowmya9854
    @sarangsowmya9854 Před 2 lety

    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 ?

  • @vetal3513
    @vetal3513 Před 3 lety

    so, the useMemo hook hasn't any profit with the simple types variables as string, number, boolean?

  • @silvanadonato7869
    @silvanadonato7869 Před 3 lety

    useEffect and its dependencies... 🤔 not too clear, I thought that the array of useEffect had something to do with component update.

  • @zxginay3962
    @zxginay3962 Před 3 lety

    it basically starts at around 5:00

  • @zlackbiro
    @zlackbiro Před 4 lety

    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

  • @varuncharan9109
    @varuncharan9109 Před 2 lety

    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 ?

  • @elenaconn6412
    @elenaconn6412 Před 3 lety

    "When I hit the clicky.. clicky clicky..."

  • @limitless9483
    @limitless9483 Před 3 lety

    8:40 Referential equality

  • @batuhansahan
    @batuhansahan Před 3 lety

    Why didn't you used array within useState

  • @NITESHSINGHNRS
    @NITESHSINGHNRS Před 4 lety

    please remove mic from keyboard.......its itterate ....but good explained.

  • @user-vn2nx1yq9e
    @user-vn2nx1yq9e Před 4 lety

    не пей пиво перед записью

  • @Jitendra0712
    @Jitendra0712 Před rokem

    Hi

  • @okbrk
    @okbrk Před 3 lety

    Slowest typo skills I've ever seen but good tutorial though