10 React Hooks Explained // Plus Build your own from Scratch

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

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

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

    The React documentation should link to this video.

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

      That google listening to your thoughts and the algo working in the background lol

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

      This channel's videos aren't beginner friendly.. It only helps people who are already familiar with this stuff.

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

      @@TheSaintsVEVO not in this case. This video is just a copy of the official (poor) docs.

    • @Zach-s5g
      @Zach-s5g 3 ปีที่แล้ว +48

      @@TheSaintsVEVO not really.
      This video is much better. The docs is.. shall I say confusing

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

      @@TheSaintsVEVO If you find something you dont know, research it and come back. This applies no matter what level youre at. Id say a beginner would get more out of this video than an expert.

  • @RohitSharma-vq2gn
    @RohitSharma-vq2gn 3 ปีที่แล้ว +1010

    Hours of react knowledge distilled in 10 mins. Felt like stealing. Thanks man, great work!

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

      ever noticed stolen things taste better than bought? ... except bricks... those taste the same

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

      facts, time is money bro that's the reason and we are lazy asf

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

      i really thought i would be learning react hooks in 1hr but this guy did in 10 mins, superb!

    • @WellActualllyyy
      @WellActualllyyy 11 หลายเดือนก่อน +2

      nice man i still don’t get it

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

      @@WellActualllyyy it will make sense eventually, just keep coding

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

    Learned more about hooks in this single video than all my attempts to learn about them over the past several years!

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

      Interesting, because this video doesn't say anything more than the official guide.

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

      @@rafadydkiemmacha7543 you're right, but the official documentation never felt welcoming enough to read through all the hooks.

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

      @@CodeSketched I completely agree and in my opinion, this video is not welcoming neither. One of the worst ones so far.

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

      @@rafadydkiemmacha7543 MOVE ON Hater

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

      @@shashikanthp3145 so it's not allowed to express opinions anymore, sheep?

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

    One thing alot of people miss is that on useState in the setter you can actually pass a function to get the prev state value you for say updating a counter which is the correct way. For example setCount(prevCount => prevCount + 1). if you where to call setCount and try modify the value based on the current count value the state would be modified based on the value at that render time. If you call setCount(count + 1) twice it would only infact increase the value by one as both calls would get the prev rendered value and overwrite each other. Hope this helps

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

      wow i knew that we should use prevcount but never truly knew what could go wrong if i didn't. Thank you man.

    • @KhiemKimDoPkmn
      @KhiemKimDoPkmn 10 หลายเดือนก่อน

      aaaaaAaAaa​@@souvikchakraborty9900

    • @JesseNewbold
      @JesseNewbold 21 วันที่ผ่านมา

      ty, knew what my error was but couldn't figure out how to solve it until i ran across this comment

  • @Surya-np1bb
    @Surya-np1bb 2 ปีที่แล้ว +9

    When I wanna know about a topic and fireship has already made a video about it is the best feeling. This guy can concisely teach any topic.

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

    now I'm happy that I started learning React in 2022 too lol. I just skipped this whole class thing.

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

      same lol. Class components are so confusing to me but hooks makes it sooo much easier to understand lol.

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

      @@thelonercoder5816 haha yeah! felt good we can just skip what was a major pain in the butt for a lot of devs in the past

    • @CST1992
      @CST1992 7 หลายเดือนก่อน

      You want to know them, just in case you need them. I've been using React since 2019 and I have started with class components. They are, you can say, just a more explicit way of doing the same thing you are doing with hooks. For me it's backwards: instead of getting to use a separate function componentWillUnmount(), I have to remember that the function returned from useEffect() does the same thing.

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

    You explained the whole feature set of the major change React has had in years in 13 minutes! That's just unbelievably awesome! ❤️

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

    This video is must of every react developer. He made everything so simple and easy to understand and that to about so much of react features in just 13 minutes.

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

    Been working with react over 9 months now, learn something new everytime I watch one of your react videos. 🤯

    • @vikas7769
      @vikas7769 3 ปีที่แล้ว

      Bro I need some help

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

    Wow, It was actually easy to understand the core concept of the hooks in just 10min, I have seen 40min that could not explain a hook as good as this video. Great work.

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

    Dude I'm in love with this channel, speed is perfect, finally someone who is not wasting 5 mins begging for subscribe, or speaking about his life or unrelated topics... And someone who is not writing code, testing and debugging in front of us... this is just perfect srsly... Keep up the perfect work!

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

    This is the only video i have found helpful. it's been a week and i have been struggling with react hooks. I am used to writing classes. Hooks feel very intimidating to me but after watching this video, i feel confident in using hooks instead of writing classes. Thank you for such an easy explanation

    • @Fireship
      @Fireship  3 ปีที่แล้ว

      Glad it helped!

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

    You have me *”hook”* ed to this channel.

    • @Onserio.
      @Onserio. 3 ปีที่แล้ว +8

      Boooooooooooo!

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

      Yeeeessssssssss!

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

      go ahead and clock out for me

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

      now thats how you useContext()

    • @aw1lt
      @aw1lt 3 ปีที่แล้ว

      HAHAHA bye.

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

    I watched hours video for understanding React Hooks. This video did unbelievable, so easy, just 13 minutes. Thank you from Azerbaijan.

  • @kawsar.130
    @kawsar.130 2 ปีที่แล้ว +13

    One of the best explanations of React Hooks. Thank you for good stuffs 👌

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

    I just took an entire college course focused on React, and I learned way more from this video

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

    You youtube channel is simply dream come true for a developer. Short videos, great explanations, etc. It is just awesome

  • @Technoholicplus
    @Technoholicplus 3 ปีที่แล้ว

    This is is the only video that not only cleared my hooks concept, but also shows the shortcut method to write eventhandling and state change in one line i.e. ( setNum(num+1)}>plus ) Thank you so much.

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

    This is literally the best youtube channel I have every found. THANK YOU!

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

    This is flawless, clear, concise, and thorough. You are an exceptional natural teacher.

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

    Great vid man!

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

    It is insane how well you explained all these hooks in not a lot of time without it seeming rushed/barely brushed over. Thank you!

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

    Easily the perfect mix of most informative and fun coding channel on the web.

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

    Saved my hours to prepare for interview.
    Amazed by this video.
    Thanks a lot

    • @shivanigaddagimath6105
      @shivanigaddagimath6105 3 ปีที่แล้ว

      Hi Akash! Are you still looking for job opportunities currently ? Would you be interested in exploring a job opportunity in web development?

  • @FaruhPaerhati
    @FaruhPaerhati 3 ปีที่แล้ว

    My god, you explained the concepts and more in much better fashion than toiling over the docs for a week

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

    The amount of information your videos consist is unbelievable, really appreciate your efforts

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

    Omg, today i was thinking of reviewing react hooks and this video show up, thanks!

  • @ali-celebi
    @ali-celebi 3 ปีที่แล้ว +7

    1:34 (best framework ever) - I just can't agree more :)

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

    short and simple explaination that's what devs want. this is just that.

  • @anth0ni33
    @anth0ni33 3 ปีที่แล้ว

    Wonderful information in just 10mins. You're a national treasure!!!

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

    The great ability of high-level explanations about general and wide concepts in only 13 minutes. thank you!

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

    The best React Hooks video I've seen so far.
    Thank you for providing a such compelling video.

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

    I have watched this like 17 times and I’m learning each time again lol thank you

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

    this is the most amazing, concise, digestible video i've ever watch. Huge props!

  • @MrRAHUL7777777
    @MrRAHUL7777777 10 หลายเดือนก่อน

    You completed the 3 months topic in few minutes . Great work 👏

  • @muhammadahmedjaved7691
    @muhammadahmedjaved7691 3 ปีที่แล้ว

    never ever have I seen someone explaining complex things in simple and short words like you do
    you are a professional at explaining things

  • @Chrisknot94
    @Chrisknot94 3 ปีที่แล้ว

    Niiice another concise hook video in plain english. This is why this is my favourite dev channel 👍🏻👌🏻

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

    This is really helpful for me. I started learning React without understanding component life cycle completely and was struggling a bit. Now I can useRef() of this video. Thanks!

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

    It's definitely a tough chunk to digest but it's really interesting to have a peak at what react is since I always looked the other way toward angular and vue

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

    Thank you very much Fireship.. So much to learn from single video.

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

    In addition to the *useImperativeHandle* hook: you can use this if you have both a *forwardRef* and a *useRef* in your component that you want both to be assign to the same element. You can use the *useImperativeHandle* hook to assign the regular *useRef* ref to the *forwardRef* ref. This is because you can't assign two refs to the same element.

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

    i was here to revise my concepts and you got it all covered in 13mins , thanks a lot .!!

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

    I have never used React before, and this video has made me that much more comfortable sticking with Vue 😅

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

      Hooks are beautiful. I have projects using both react and vue, both are awesome. I'm a react guy and i think it's easy to learn Vue if you already on intermediate level in React. But I don't know the learning curve if you learn Vue first.

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

    Well done man , I didn't expect this much clarity in just 13 minutes, but you explained everything perfectly. Thanks

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

    Saw Angular Logo with caption (best framework ever)..
    that's why I'm subscribed. lol

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

    1:35 @BenAwad

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

      was about to say that too

    • @lucass5852
      @lucass5852 3 ปีที่แล้ว

      Glad I wasn't the only one who thought about this, what would he say about it lol

    • @albertrisenielsen1405
      @albertrisenielsen1405 3 ปีที่แล้ว

      Yeah watching both of these seem like heresy on some level

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

    Another awesome video. I love React hooks. I just recently started diving into writing custom hooks.
    It has been an excellent way to create reusable functionality as well as not stuffing all the logic in one file.
    Thanks for this video.

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

    For non-native English speakers, I'd recommend watching the video at 0.75 speed.
    Pretty dense (yet high quality) information.

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

    Many videos I saw but this one is simple specific and easy to understand… thanks

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

    So simple and useful! Thanks a lot for explaining these things in the most understandable manner.

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

    brilliant to watch just before a interview :)

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

    Most useful video I’ve watched on hooks

    • @lukas.webdev
      @lukas.webdev ปีที่แล้ว

      I just posted a video on a similar topic (in 2023) - maybe this could be interesting for you as well. 😉

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

    - 1:34
    - Ben Awad has entered the chat

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

    Thanks!

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

    I always come back to this video to a fast/clean explanation of react hooks ! Thanks for the content my man ! Amazing :)

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

    1:33, yes! Angular the best framework ever ❤❤❤❤❤❤❤❤❤

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

    Love the pace you have in your videos. And the visuals is just stunnig

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

    I wish I had seen this video when I began learning hooks. Took me months of study and practice to understand them fully. This would have been a good entry point. Most tutorials fall short.

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

    5:50 - for alert() to run when component is removed from DOM, second argument (dependencies) of useEffect() should still be empty array []. Without empty array dependency code does not work as intended.

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

      The channel is amazing, this should be corrected.

  • @wardenpataski2882
    @wardenpataski2882 3 ปีที่แล้ว

    I kinda struggled to understand how to create a custom hooks before, but now I understand it after watching your explanation thank you :)

  • @albertkim1809
    @albertkim1809 2 หลายเดือนก่อน

    Thank you for this video - as a boomer coming from the old class-based ways, I wasn't up to speed on all of the built-in hooks.

  • @shaheenumar4926
    @shaheenumar4926 3 ปีที่แล้ว

    Every second is worth watching this channel.❤️

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

    Hell yeah bro. Angular saves me so many headaches. 🙏😍

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

    I am watching this before my interview and it is helping me with my anxiety...
    I am feeling calm...

  • @hobbiesandmore5633
    @hobbiesandmore5633 3 ปีที่แล้ว

    I stumbled on this video but I’m glad I did!
    I was looking for ways to implement hooks in my program but had no idea what to do with them. When I watched this video I had a “Oh, THAT’S what it does” moment occur multiple times.
    Thanks for making this!

  • @Lifeincuts
    @Lifeincuts 10 หลายเดือนก่อน

    This video really helped me a lot, Im doing the Meta certification but they guy explaining this on the course sounds like an NPC.
    Thank you Jeff!

  • @HugoSanchez-kd7qz
    @HugoSanchez-kd7qz 7 หลายเดือนก่อน

    Thank you for this! Used this a refresher and absolutely loved it. Wish we had a few more examples of each hook.

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

    After last working with React in 2016, coming back to it again is super confusing. But this video got me up to speed real quickly!

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

    You always manage to put out a video that i just need in that exact moment. Simply amazing. Keep up the good work

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

    This channel is the fresh breath of air for devs♥️

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

    Thanks ! This is so comprehensive and entertaining.

  • @vishmapdas7898
    @vishmapdas7898 3 ปีที่แล้ว

    I have a feeling that you will add much value to my life. Liked and Subbed.

  • @gracewood6768
    @gracewood6768 3 ปีที่แล้ว

    best of the best. I never understood each of them but now I got a grasp about it.!

  • @steelwolf180
    @steelwolf180 3 ปีที่แล้ว

    Really easy to understand and helps to point me in the right direction. For a problem, I was stuck on solving a UI component not updating by itself till I click on another component.

  • @zacktaylor1143
    @zacktaylor1143 3 ปีที่แล้ว

    Your UseEffect explanation was brilliant.

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

    1. useState
    2. useEffect
    3. useContext
    4. useMemo
    5. useCallback
    6. useRef
    7. useReducer
    8. useImperativeHandler
    9. useLayout
    10. useDebugValue
    not in order of the video.. tho. lol
    Very informative video. Thanks!!!
    Even 8 and 9 is described as rare, I actually use these very often when building more complicated UI/UX.

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

    Woaw, the best 13 mins of my entire life :D

  • @pjalex98
    @pjalex98 3 ปีที่แล้ว

    I have survived just with useState, useEffect and useReduce hooks, and now I can try to understand the others to implement in my projects by watched this video.

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

    Wow, I had a really hard time figuring out precisely how hooks were working until I found this video. It's so clear and explaining the fundamentals (the key). I'm literally looking for a way to join any newsletter you have because I love the way you communicate complex principles.

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

    I am learning React and this is the video I needed

  • @rain-techstudio2567
    @rain-techstudio2567 2 ปีที่แล้ว

    This is amazingly easy to understand with just 10 minutes!! Thanks a lot great man!

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

    Angular bois finally got some love.

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

      Dozens of us are so happy. DOZENS!

    • @juniordev4190
      @juniordev4190 3 ปีที่แล้ว

      @フルブライトケネス what r u talking about? V12 has just launched.

  • @kurtthorsten4463
    @kurtthorsten4463 3 ปีที่แล้ว

    srsly your content is insane man. thank you thank you thank you

  • @ffelaar
    @ffelaar 3 ปีที่แล้ว

    you are ridiculously good at explaining things succinctly in a short amount of time - thank you for this great content.

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

    I'm not a native speaker, so it's sometimes hard to understand for me. But I'm surprised how clearly you explained hooks. It was realy useful. Thank you..

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

    Excellent video on React Hooks.

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

    This was amazing, it took me over an hour to write down the notes so much knowledge

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

    One thing to note about `useCallback` is that it isn't _just_ needed to improve performance. Sometimes, we need it because a useEffect depends on the function which can cause infinite loop scenarios. So basically, useCallback can save us from these infinite-loops!

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

      Yeah, but only if you include all functions/variables in your dependency array, like EsLint/TS wants you to do..

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

    To avoid bugs in your case you should rather use setCount(prev => prev + 1) instead of setCount(count + 1).

    • @codeaperture
      @codeaperture 3 ปีที่แล้ว

      True👍

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

      Can you elaborate on how this method results helps avoid bugs compared to the other method?

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

      @@arpansaha5638if you need to set state based on previous state, you should use a callback function that receives a previous state as the first argument

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

      @@arpansaha5638 Beacause if you run setCount(count + 1) twice very close to each other, count won't be updated for the second call. Meaning count will be added 1, instead of the expected 2. Meanwhile, if you use prev, React ensures the count is updated before the next call.

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

    Great/quick explanations of each hook, super helpful thanks

  • @3mro_coding
    @3mro_coding 3 ปีที่แล้ว

    Maan! I love taking tour in your channel you deliver clean and conscious contents.

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

    easy to understand,good hook summary for begginers !

  • @anuragnair5672
    @anuragnair5672 3 ปีที่แล้ว

    Get this man a medal!

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

    Very crisp and precise as always 👌👌

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

    Even if these videos don't explain stuff in detail, they sure give an overview of the topics......which is a huge deal to IT students like me whose textbooks don't even cover Git or ES6!!!!

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

    Thanks for the Video. I know now that i will stay with Svelte.

  • @day2dayja110
    @day2dayja110 3 ปีที่แล้ว

    Where was this video a year ago!!!!!! EXCELLENT!!!!!! 10000/10

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

    Man! That "Angular best framework ever" was the only thing I needed after watching few Ben Awad videos.

  • @HenningGu
    @HenningGu 3 ปีที่แล้ว

    You have no idea how much I need this

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

    Done thanks
    React hooks can be used only at the top level inside the functional component function definition.
    Hooks:
    useState
    useEffect make sure to provide dependencies array, if no dependencies then pass empty array
    useEffect can have a cleanup function by returning a function from the useEffect callback, will be called when component un mounts
    useContext lets you share state from a parent component to child components without having to pass props down
    useRef use when you want to grab a reference to an html elements and programmatically. useContext lets I access the context from the context provider up the tree
    useReducer is a better alternative to useState as it allows you to dispatch events or actions from ui elements then handle these events in the reducer function. useReducer takes the reducer function which takes the state and the dispatched action so you can do a switch case in the reducer and handle them
    useMemo to cache computationally expensive values so that they aren’t recalculated on every render. Takes a dependency array like useEffect to decide when to recalculate the value
    useCallback is like useMemo but it caches an entire function definition. When you define a function in your component, that function gets redefined after every render. useMemo causes the return value to be cached, so the function isn’t run on every rerender but with useCallback the function isn’t redefined on every render. This is useful when ui elements have a reference to that function like if it’s an onclick handler. When that function is redefined the component that has reference to it will get rerendered and useCallback prevents this, it is useful when many ui elements have reference to that function
    useImperativeHandle