Mastering React's useEffect

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024

ความคิดเห็น • 407

  • @joonkim9302
    @joonkim9302 2 ปีที่แล้ว +124

    This is by far one of the most useful videos I have watched over my 10 years of youtube watching career. seriously. I wathced it twice yesterday, didn't get it. Rewatched today and get everything. Absolutely great video.

    • @jherr
      @jherr  2 ปีที่แล้ว +4

      Wow, thanks!

    • @ToddDunning
      @ToddDunning 2 ปีที่แล้ว +3

      Joon I see your 3 watch attempts and raise you two.

    • @zmrzlinazmrzlina2094
      @zmrzlinazmrzlina2094 2 ปีที่แล้ว

      @@jherr Thanks for code included!

    • @yawn74
      @yawn74 5 หลายเดือนก่อน

      I just watched this, and this video is trash literally there is no point to call use effect here when you can literally remove useEffect and call them normally.

  • @Crevulus
    @Crevulus 2 ปีที่แล้ว +97

    I thought I'd just about mastered useEffect but this taught me even more. Especially about what react does under the hood. Your videos are a goldmine.

  • @sayantanmanna1360
    @sayantanmanna1360 ปีที่แล้ว +5

    Kudos to TH-cam algorithm for recommending this gold mine!! Every time I re-watch the same lecture, I learn something new from it. Even the shorts are too useful. Thanks for all your effort mate!!

  • @OleksandrDanylchenko2k
    @OleksandrDanylchenko2k ปีที่แล้ว +4

    The useCallbackRef pattern is EXACTLY what I was missing in my mental puzzle to properly memoize passed functions. Thanks 🙏

  • @onthecodeagain
    @onthecodeagain ปีที่แล้ว +10

    Every react dev should watch this video. You explain concepts so clearly and at such a good pace! All your content is so good man!

  • @lukeotwell3296
    @lukeotwell3296 2 ปีที่แล้ว +18

    This is one of the best break downs of a hook I have seen, hope to see more like this.

  • @arkadyvinkovsky5879
    @arkadyvinkovsky5879 ปีที่แล้ว +2

    Best explanation of useEffect I have ever seen. Thanks so much!

  • @raymondmichael4987
    @raymondmichael4987 2 ปีที่แล้ว +4

    That last part, using state as dependence I didn't know that.
    This video is packed with lot of very important lessons. Thanks buddy.
    Greetings from Tanzania 🇹🇿

  • @benrobo8
    @benrobo8 2 ปีที่แล้ว +2

    This is really cool. I once taught I knew all about useEffect, but watching this made me realize I never new nothing. Love how you broke it down. Keep it up

  • @zzzzzzzzdsadasd
    @zzzzzzzzdsadasd 2 ปีที่แล้ว +16

    at 18:00 you used useLayoutEffect, why? It seems redundant, not performant and adds code complexity for no reason.
    Any reason for not just doing the following?
    const savedOnSuccess = useRef(options.onSuccess);
    savedOnSuccess.current = options.onSuccess;

    • @jherr
      @jherr  2 ปีที่แล้ว +9

      You are correct, I didn't need to do that.

  • @sayeddileri3461
    @sayeddileri3461 หลายเดือนก่อน +1

    For those slightly confused about what exactly he means by references…put simply a reference is just the address of a memory block.
    For example, your variable which is assigned to an object doesn’t hold the actual definition of that object, it holds the value of the memory address which contains the stored object.
    So it’s just pointing to that memory address block which contains the object.
    If I assign variable X to variable Y which is assigned to an object, then variable X is simply pointing to the same memory address as variable Y.
    Hence why variable X can mutate the original object defined by variable Y.
    JavaScript Objects, functions, arrays and other composite types like dates, sets, maps and etc…

  • @kirkir2297
    @kirkir2297 ปีที่แล้ว +2

    Absolutely best explanation about how useEffect dependencies work! 🔥🔥🔥

  • @bishalpandit4464
    @bishalpandit4464 2 ปีที่แล้ว +6

    This video literally cleared up a lot of confusions. Really grateful. This video is a gem 💎

  • @azmaniandevil
    @azmaniandevil 2 ปีที่แล้ว +2

    this is genuinely one of the best videos I've watched explain a seemingly complex concept. once broken down into the fundamentals, paired with straightforward examples (and gotchas!) - the complexity goes way down.
    thank you Jack! I was in the middle of a large refactor to reduce our eslint errors and the only one remaining is the useEffect dependancy array ones. this video definitely is going to help me tackle the more complicated ones from that.

    • @jherr
      @jherr  2 ปีที่แล้ว

      Fantastic! Thank you! And, of course, good luck!

  • @wandersonsousa1891
    @wandersonsousa1891 2 ปีที่แล้ว +1

    The stopwatch example was mind blowing, thank you, for the good work !

  • @nairanvac79
    @nairanvac79 2 ปีที่แล้ว +3

    Thank you so much for this. I've been struggling with this for weeks!

  • @habtamudesalegn5397
    @habtamudesalegn5397 2 ปีที่แล้ว +4

    very clear and an in depth uses of some of react hooks, thanks Mr. Jack as a usual!

  • @gabrielfono844
    @gabrielfono844 ปีที่แล้ว +1

    damn
    I have been working as full stack engineer for 7 months now but I swear I have to watch this video three times to fully understand .
    this is one or if not the most underrated videos on youtube on useEffect .
    I trully understand how this things work.
    some people think they understand pass by reference but most developers dont understand these concepts.
    I will share this video for sure.
    I spent this weekend to go over his videos on useLayout, useCallback ,useRef and so on.
    thanks a lot.

  • @aarongillies2900
    @aarongillies2900 2 ปีที่แล้ว +2

    Fantastic explanation of a sometimes frustrating hook in React, definitely bookmarking this one!

  • @vikashnagar2114
    @vikashnagar2114 ปีที่แล้ว +1

    really help a lot! This is most deep dive video , I ever seen in coding journey

  • @Kaiyes_
    @Kaiyes_ ปีที่แล้ว +2

    hands down the best teacher of React. I kid you not !!!

  • @AZisk
    @AZisk 2 ปีที่แล้ว +1

    Jack, just found your channel today. Really great content 🎉 thanks for the crystal clear explanation that are built up like a gradual layering of knowledge and skill. This is how tutorials should be.

  • @joelalmeida5249
    @joelalmeida5249 2 ปีที่แล้ว +4

    Excellent video, excellent channel. The examples you bring are amazing and the way you explain the content, step by step, is really cool. Hello from Brazil!

  • @michaelbacy3525
    @michaelbacy3525 2 ปีที่แล้ว +1

    The way you explain these topics is amazing

  • @AnupDhakalSharma
    @AnupDhakalSharma 2 ปีที่แล้ว +1

    The title and thumbnail are opposite of click bait. I almost didn't click it thinking I'm gonna get the same basics, aren't I? Boy was I so wrong
    I am glad that I clicked it.

  • @apresthus87
    @apresthus87 2 ปีที่แล้ว +2

    This is easily one of the best code related (at least when it comes to React) videos I have ever watched. I thought I had a pretty good idea about how useEffect worked, but I learned a lot from this and deepened my understanding. I'm sure there are optimisations I can do in my codebase now armed with this knowledge :)

  • @DarkFlarePrince
    @DarkFlarePrince 2 ปีที่แล้ว +1

    Best channel I've found so far!! Thank you so much!!

  • @julian_pp
    @julian_pp 2 ปีที่แล้ว +4

    A season mastering for all hooks please! Thank you for this vid! Much appreciatted

  • @smoothbeak
    @smoothbeak 2 ปีที่แล้ว +1

    Just discovered your channel now, and I'm very impressed with the lucidity of your explanations!

  • @mateuszrychlik4292
    @mateuszrychlik4292 2 ปีที่แล้ว +1

    Your videos actually helped me a few times at work. Hope you'll keep up uploading

  • @tomasvancoillie
    @tomasvancoillie 2 ปีที่แล้ว +1

    Great explanation about useEffect. It is a hook with some complexity. Just last week had an example in a pretty large useEffect to programmatically set some form fields based on other filled in fields. In the useEffect, we needed a value to compare to other fields. But had the problem at first that the value kept triggering the useEffect hook undesirably. When creating a reference to that value, the useEffect hook wouldn't trigger when we used that value inside the hook. Learned a lot ;)

  • @aham_sammich
    @aham_sammich 11 หลายเดือนก่อน

    Thank you for the video! I'd been having trouble on a project recently, but I realize now what I'd been doing wrong!

  • @elmoutaouakkilmohammed1432
    @elmoutaouakkilmohammed1432 ปีที่แล้ว +1

    Amazing! Watching this video is like watching a great movie multiple times, and it just gets exciting and fun every time you watch it!
    Thank you, Jack!

  • @yogi2983
    @yogi2983 ปีที่แล้ว

    I've seen seasoned developers make the mistakes you've shown in the video. Thanks a million for this! I'm a big fan

  • @rboy879
    @rboy879 2 ปีที่แล้ว +1

    Woow blown away but the explanation, use case etc. Keep up the good work!!!

  • @mokorra
    @mokorra 2 ปีที่แล้ว +1

    Quality video as always Jack! Now I know I never understood useEffect dependency till I watched this video

  • @LuisBlancoAustin
    @LuisBlancoAustin 2 ปีที่แล้ว +1

    What an awesome explanation of the react useEffect hook. Many thanks!

  • @tiagodroppa
    @tiagodroppa 2 ปีที่แล้ว +2

    So much value in one video!

  • @ontheruntonowhere
    @ontheruntonowhere ปีที่แล้ว +3

    Great content, Jack. I'm a PHP dev who's getting into React, and I've started binging your channel. I don't mean this as criticism, just giving some feedback on a couple of things which made the video somewhat difficult to follow. I realize this video was released a while ago so apologies if these points have already been addressed. First, is it possible to turn off hinting in VS Code? The popups while you're typing are distracting, and obscure your work. In the same vein, it would be easier to follow if your headshot wasn't obscuring the code, perhaps by being smaller or hidden altogether when you're not talking directly to the camera. Thanks for providing these tutorials. As a vlogger I recognize how much work goes into making them.

  • @diaael-din8832
    @diaael-din8832 2 ปีที่แล้ว

    okay i must admit that, u r amazing, i hv been coding for almost a year now (not much i know) but built few apps alrdy, but once i saw ur video i knew i'm missing few things and also did some mistakes with these apps, and gotta say also ur teaching is awesome, hope u and ur channel best of luck, ty

  • @Irfan-vl6ij
    @Irfan-vl6ij ปีที่แล้ว +1

    Best Video to learn about useEffect

  • @noormuhammad888
    @noormuhammad888 ปีที่แล้ว

    Gold mine of knowledge thats even for free... ! Highly appreciated sir

  • @asagiai4965
    @asagiai4965 ปีที่แล้ว +2

    Very nice and informative video. Also, encourage people to be not afraid of useEffect. But also promotes critical thinking.

  • @bythealphabet
    @bythealphabet 2 ปีที่แล้ว +1

    Excellent Video Jack thanks.

  • @Rei-m3g
    @Rei-m3g 2 ปีที่แล้ว +1

    Am going to tear all my hair out working with this useEffect .😱

  • @qcmira2024
    @qcmira2024 ปีที่แล้ว

    I love how knowledgeable you are in React and state management and how you make complex stuff easy to understand. I wish you had a comprehensive React course. I would have definitely bought it in the blink of an eye.

    • @jherr
      @jherr  ปีที่แล้ว

      I have a react and typescript playlist for free which is pretty comprehensive.

    • @anandv1391
      @anandv1391 ปีที่แล้ว

      ​@@jherrwhere man I want to buy

  • @vibhor3049
    @vibhor3049 2 ปีที่แล้ว +1

    Amazing video, Jack! You're very knowledgeable and underrated. Keep creating!! 🔥

  • @collenzaligway4458
    @collenzaligway4458 2 ปีที่แล้ว +1

    Really helpful Man, I appreciate your videos that has quality content and eloquent explaination of process. Thank you so much.

  • @shashikaxp1
    @shashikaxp1 2 ปีที่แล้ว +1

    Now we are talking, thanks Jack. loved this. we need some advanced stuff on react :)

  • @sagarreddy7461
    @sagarreddy7461 2 ปีที่แล้ว +1

    Awesome jack. Got clear idea of useEffect now. Thanks.

  • @FeralWitchchild
    @FeralWitchchild 2 ปีที่แล้ว +1

    Jack, this is extremely well done, thank you for this!

  • @hikarukun5126
    @hikarukun5126 ปีที่แล้ว +1

    I am glad that I discovered this channel, thanks a lot Sir for your passion to educate people and making our community better

  • @yashwantsahu3002-ram
    @yashwantsahu3002-ram ปีที่แล้ว +2

    Hello Sir. Love from India i love your content. It just great to have that much of insight of React there thanks fro creating such type of content.

  • @Raubritterr222
    @Raubritterr222 2 ปีที่แล้ว +6

    Jack, can you please make a video on how to set up VSCode for React development? You are an excellent expert in both!

  • @beders
    @beders 2 ปีที่แล้ว +2

    I'm so happy I'm using reagent which has absolutely none of these problems

  • @jaimearriola1495
    @jaimearriola1495 2 ปีที่แล้ว +1

    Why I didn't know about this channel before? ... I mean you're an awesome instructor!! I enjoyed this video so much and I learned a lot!! Thanks so much for this great content, you just got a new suscriber! 🥳

  • @rashidaz1582
    @rashidaz1582 ปีที่แล้ว +1

    Thank you Jack! Amazing explanation

  • @vizunaldth
    @vizunaldth 2 ปีที่แล้ว +1

    So one of these for all the important ones plz!

  • @javaforliving
    @javaforliving 2 ปีที่แล้ว +1

    Excellent video as usual, Jack !

  • @SushilKumar-ig8ls
    @SushilKumar-ig8ls 2 ปีที่แล้ว +1

    Thank you for such great insights and tricks. Lot of respect and a BIG THANK YOU.

  • @abdulazeez.98
    @abdulazeez.98 ปีที่แล้ว

    Awesome video! finally a video that covers them well.

  • @onticmix
    @onticmix ปีที่แล้ว +1

    Your content is amazing as always! Thanks for doing what you do!

  • @vibhassingh619
    @vibhassingh619 2 ปีที่แล้ว +1

    Wow this tutorial is awesome. This is a very deep explanation. Worth watching it. 😍

  • @MuhammadAhmed-pd8zu
    @MuhammadAhmed-pd8zu ปีที่แล้ว +1

    You are beyond amazing! Thank you so much for this tutorial!

  • @anders671
    @anders671 2 ปีที่แล้ว +1

    Excellent material!

  • @shubhamlatiyan7972
    @shubhamlatiyan7972 2 ปีที่แล้ว +1

    Always been a fan of your tutorials

  • @KorhalKk
    @KorhalKk ปีที่แล้ว +1

    When you've put the useFetch inside the useEffect I've already knew it would loop because useEffect is activated at every rendering, if you don't condition or apply that last array parameter, it will loop everytime.

  • @muratasarslan2359
    @muratasarslan2359 2 ปีที่แล้ว +1

    Thank you for your valuable effort Jack 👏

  • @johnelbasha8967
    @johnelbasha8967 ปีที่แล้ว +1

    The part of the video between 3:51 and 5:20 explains very well the render and re-render lifecycle. I urge anyone who is still a bit nervous about useEffect to watch and rewatch this section til it sticks. I had to draw a diagram to explain to myself what was happening at each step.
    Also, if you're using console.log within the useEffect hook, don't forget to make sure that there isn't a React.StrictMode component within the index.js file.

  • @drewbird87
    @drewbird87 2 ปีที่แล้ว +1

    Incredibly valuable again Jack. Thank you 🙏

  • @jonathanzevi2425
    @jonathanzevi2425 2 ปีที่แล้ว +1

    Superb tutorial! I wish I found you sooner.

  • @kavinduchamith8005
    @kavinduchamith8005 ปีที่แล้ว +2

    This content is gold. 💯

  • @teerapatprommarak2070
    @teerapatprommarak2070 2 ปีที่แล้ว +1

    Great explained, thank you Jack!

  • @vorche_
    @vorche_ ปีที่แล้ว +1

    Loved the video thank you!

  • @zerocodercool
    @zerocodercool 2 ปีที่แล้ว +1

    Grrrrrreat explanation, as always! Thanks Jack!

  • @abdulazeezatanda2371
    @abdulazeezatanda2371 2 ปีที่แล้ว +2

    Awesome master class! Could you please tell me what VSCode extensions you used for the following in the video:
    - the font styles
    - the code suggestions
    - the theme

    • @ajithsimon
      @ajithsimon 2 ปีที่แล้ว +1

      I just want to know, which code suggestions plugin he using. Have you figured it out already?

    • @abdulazeezatanda2371
      @abdulazeezatanda2371 2 ปีที่แล้ว

      @@ajithsimon No, I haven't yet

  • @echobucket
    @echobucket 2 ปีที่แล้ว +3

    One thing that's helpful when thinking about useEffect is that it's like a callback.. and it's gonna get called by react AFTER the component function ENDs.

  • @tomascarignano5002
    @tomascarignano5002 2 ปีที่แล้ว +1

    Really helpful Jack

  • @JoonhwanLee
    @JoonhwanLee 2 ปีที่แล้ว +1

    You ARE good story teller!!
    Thanks ❤️

  • @sumitwadhwa8823
    @sumitwadhwa8823 2 ปีที่แล้ว +2

    Hi Jack. Thanks for the videos. May I ask, how did you create that terminal logo.?

    • @jherr
      @jherr  2 ปีที่แล้ว +1

      That's Sixel graphics. It's really cool: th-cam.com/video/apg9XR35pAM/w-d-xo.html

  • @pranavkochhar9352
    @pranavkochhar9352 2 ปีที่แล้ว +1

    Very informative and well explained video. Thank you so much

  • @habibiSD
    @habibiSD 2 ปีที่แล้ว +1

    Amazing job so many light bulbs went off after watching this turtotial.

  • @frontend_ko
    @frontend_ko ปีที่แล้ว +1

    What an informative uncle

  • @tubagusputra5788
    @tubagusputra5788 ปีที่แล้ว +1

    It's great explanation, sir :)

  • @piltonswrangbrahma5140
    @piltonswrangbrahma5140 2 ปีที่แล้ว +1

    I came here for copper but I found gold
    You just got a SUBSCRIBED

  • @tomino133
    @tomino133 2 ปีที่แล้ว +1

    Excellent video Jack.

  • @discontinuity
    @discontinuity 2 ปีที่แล้ว +2

    Hi Jack! I love these videos, now I really understand useEffect. Can you explain a bit more about 17:18 on what you mean when using useRef with useLayoutEffect in terms of 'change this later on'?

    • @jherr
      @jherr  2 ปีที่แล้ว +6

      So useLayouEffect is an effect that gets run synchronously after the render completes. Honestly the best thing to do here is just to remove the useLayoutEffect and set the ref.current unconditionally right after the useRef call. It's zero cost to do that and there is no potential issue with re-renders since setting a ref does not force a re-render.

    • @discontinuity
      @discontinuity 2 ปีที่แล้ว

      @@jherr Awesome, thank you!

  • @imarenny
    @imarenny 2 ปีที่แล้ว +1

    Thank you so much for the video! Very Useful! :)

  • @MrPlaiedes
    @MrPlaiedes 2 ปีที่แล้ว +1

    I'm starting to turn the corner with react. I think it has served me very well, but it's time to get back to basics.

  • @kieranosgood3297
    @kieranosgood3297 2 ปีที่แล้ว +1

    Feel I mirror some others here but I feel pretty good with react but damn, that use callback ref in particular is an interesting one actually

  • @Elvis-is-king-l3s
    @Elvis-is-king-l3s 2 ปีที่แล้ว +1

    Great informative video! I didn't forget to subscribe this time. Thank you!

  • @adventurer2395
    @adventurer2395 2 ปีที่แล้ว +8

    Great video! The useEffect dependency warnings are just too damn annoying. Sometimes you know what you're doing and that you're specifically watching just one piece of state, but it still wants you to add extra dependencies which, if you add, turn into bugs. Then you gotta keep adding ignore lines to make things work the way you want to.

    • @asagiai4965
      @asagiai4965 ปีที่แล้ว

      Sometimes you just need to ignore something

  • @NinjacookieVG
    @NinjacookieVG 2 ปีที่แล้ว +1

    This is just what I needed, thanks a ton!

  • @MattMascolo.
    @MattMascolo. 2 ปีที่แล้ว +1

    This got very convoluted very quickly. Especially with the need for 4 other hooks to get it to work as intended. Will probably need to watch this a few more times to fully grasp what is going on.

    • @TheMitchingHour
      @TheMitchingHour 2 ปีที่แล้ว

      It really highlights the weakness of React. I’ve never had to worry about this low level stuff in other frameworks. I’d prefer magic to this any day.

  • @sanketbehera-t3j
    @sanketbehera-t3j ปีที่แล้ว +1

    simply awesome

  • @elfyrulais
    @elfyrulais ปีที่แล้ว +1

    I love this so much

  • @dao_jones
    @dao_jones 2 ปีที่แล้ว +8

    Why not just use useCallback in the parent component instead of implementing a callback ref on your own?

    • @jherr
      @jherr  2 ปีที่แล้ว +8

      That would depend on the caller to ensure that the function of the custom hook is correct. IMHO it's better before the hook to ensure that its own dependency behavior is correct regardless of the the parameters sent to the function.

  • @hesamhashemian9126
    @hesamhashemian9126 2 ปีที่แล้ว +1

    Thank you, Jack; I appreciate you for creating these fantastic videos. Can I ask you what tool you've used for code suggestions?

    • @jherr
      @jherr  2 ปีที่แล้ว +1

      Github Copilot.

  • @nickv5939
    @nickv5939 2 ปีที่แล้ว +2

    Jack, how do you annotate on your macbook screen like that? Is that an app for ipad?

    • @jherr
      @jherr  2 ปีที่แล้ว +1

      I use screenBrush and a cheapy drawing tablet.

  • @ShaunMcCready
    @ShaunMcCready ปีที่แล้ว

    Fantastic explanation!! I did find your head blocks the code too much at times. Perhaps shrink the size and scroll up sometimes to show the details.