Learn React Hooks: useRef - Simply Explained!

Поділитися
Вставка
  • Опубліковано 15 січ 2025

КОМЕНТАРІ • 204

  • @cosdensolutions
    @cosdensolutions  10 місяців тому +7

    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

  • @davidkurniawan1358
    @davidkurniawan1358 Рік тому +31

    This is the reason why it's hard to understand about useRef. It's so confusing but you help me to make it easier to understand. GREAT JOB!!!

  • @psychobuddha5379
    @psychobuddha5379 Рік тому +15

    I was bit suspicious when you said we will not need another video for this but you were right. Really nice explanation, I finally understand the usage of refs.

  • @Pernicuz
    @Pernicuz Рік тому +3

    These guides are incredible. You made me understand clearly in 3 videos what my teacher couldnt in 3 days

  • @TheGr33k13
    @TheGr33k13 Рік тому +18

    Great job! Your videos have been really clear and provide straight forward examples even explaining some of the gotchas of react

  • @a1x45h
    @a1x45h Рік тому +5

    Finally, I understood useRef. You explain very well my friend. Thank you!

  • @ZahidHussain-hj2dk
    @ZahidHussain-hj2dk Рік тому +3

    Best useref tutorial.....highly recommended

  • @rustam199639
    @rustam199639 6 місяців тому

    Wow... I spent hours on it, when I used states and didn't understand why its not changing it immediately... So grateful !
    Thank you man!

  • @nirajkc224
    @nirajkc224 2 місяці тому

    I watched many videos on useRef but didn't understand at all. Now it makes me really clear.

  • @dirtysouth3291
    @dirtysouth3291 Рік тому +33

    This is the BEST useRef tutorial - you are VERY good at explaining things in a decent amount of time, and you cover everything. I will try to find more useful videos on your channel, hopefully, there will also be something about TypeScript

  • @ManishGupta-nv5by
    @ManishGupta-nv5by Місяць тому

    i always found your tutorial professional without any waste.

  • @haciendadad
    @haciendadad Рік тому +2

    I really like this description, it made sense. I am a new sub and opted to be notified of all your videos. You seems like this is a good example of the new gen of code videos.

  • @SK-fq2yz
    @SK-fq2yz Рік тому +1

    Thank you very much. It really is the last useRef video i would ever need.

  • @ofek_x
    @ofek_x 2 місяці тому

    This video helped me a lot! Great examples! Keep up the good work :)

  • @erickchavez4551
    @erickchavez4551 Рік тому +9

    I think I'm starting to get this hook. Easy to follow examples 👍. Also, it's great that you use the dark mode, my eyes appreciate it.

  • @adrianayon5513
    @adrianayon5513 Рік тому +2

    Thank you, very good explanation!! You helped me a lot!!

  • @yongdiamond2301
    @yongdiamond2301 4 місяці тому

    When he said after watched his video you don't to watch another video with same content again. For me yup because clearly simple and explanation there actually no need.

  • @HamzaAhmad-e2x
    @HamzaAhmad-e2x Рік тому +2

    Thanks, you explained it in a very simple way👌. I want to learn Express from you.

  • @KrishanMalinda-z9i
    @KrishanMalinda-z9i 2 місяці тому

    It's really understandable. Thank you ❤

  • @srsh12345
    @srsh12345 3 місяці тому

    thank you for the explanation. this hook makes a lot more sense to me now

  • @a_maxed_out_handle_of_30_chars

    wow, simple and to the point
    thanks a lot :)

  • @vesa95
    @vesa95 Рік тому +3

    Love this series!!! 🤗

  • @Engr.SharoonHoney
    @Engr.SharoonHoney 7 місяців тому

    That's amazing explanation of useRef on whole UA-cam. Thanks sir 👍

  • @baciusebastian6361
    @baciusebastian6361 Рік тому +1

    really good explanation, thank you for the video, really appreciate it

  • @arushraj3807
    @arushraj3807 4 місяці тому

    Amazing explanation 🎉

  • @prithuadhikary720
    @prithuadhikary720 3 місяці тому

    Great explanation. Thanks!

  • @핑구-s3g
    @핑구-s3g 6 місяців тому

    Amazing, I enjoy watching your React lectures!

  • @KyawMyo
    @KyawMyo 24 дні тому

    really nice explanation. thanks a lot.

  • @woodzeppelin3241
    @woodzeppelin3241 4 місяці тому

    A really good deep dive on hooks for me. Thanks

  • @dhruvdonsahu9972
    @dhruvdonsahu9972 3 дні тому

    thanks buddy, a pretty good video keep it up!

  • @benihahitti3513
    @benihahitti3513 6 місяців тому

    Earned a subscribe! Thank you for explaining this super clearly and explicitly.

  • @official_youtube_1
    @official_youtube_1 Рік тому +3

    great explanation, Exactly what I was looking for
    It clears many doubt about state vs ref.
    count a like from me.

  • @TuneTrekMusics
    @TuneTrekMusics 18 днів тому

    Thank you brother go ahead👍🏻👍🏻

  • @syuo5051
    @syuo5051 7 місяців тому

    Many thanks for this clear explanation. 💗💗

  • @vincetamayo9669
    @vincetamayo9669 10 місяців тому

    very clear and concise tutorial. thanks for this content

  • @melikarazavi3599
    @melikarazavi3599 Рік тому

    useRef is very complicated for me , you make it simple .Thank you a lot!

  • @Arnav404
    @Arnav404 9 місяців тому

    love your explanation. every thing is clear now about useRef, thanks!!

  • @vishalupadhayay6391
    @vishalupadhayay6391 Рік тому +3

    Nice video and appreciate the time and effort that you put into developing quality content.

  • @altan183
    @altan183 11 місяців тому

    Very clear and concise, thank you for the explanation.

  • @es7729
    @es7729 9 місяців тому

    You're the type of tutor we just want to hit that like button for without first having to watch the video, because previous videos were on point!
    Thanks!
    + would you also mind if I were to explain these hooks but in other language with credit like "Inspired by: Cosden Solutions"?

  • @morofernando639
    @morofernando639 Рік тому

    Absolutely another wonderful tutorial after I watched this video I can say that I am super confident with working with useRef your explanation is really straightforward and clear

  • @cheiguerabdelwehab6802
    @cheiguerabdelwehab6802 Рік тому

    Thank you so much, this video helped me in my interview, specially the re-rendering part

  • @julienheng3880
    @julienheng3880 Рік тому

    you did an excellent job in explaining things with examples in short amount of time. Give me more tutorials lol

  • @kasiakordys266
    @kasiakordys266 Рік тому

    I have watched it 3 times and finally got it :-) thanks, great explanation

  • @alejandroluisacosta2164
    @alejandroluisacosta2164 4 місяці тому

    Nice example. Thanks

  • @pranavjaiswal2379
    @pranavjaiswal2379 Рік тому

    Thanks for the clarification i really understood the difference between the useref and usestate you made my 12 minutes worth

  • @eliyahutarab4862
    @eliyahutarab4862 Рік тому +1

    Clear and simple thank you

  • @zambidzhelov6734
    @zambidzhelov6734 Рік тому

    This is the best useRef tutorial . Thansk !

  • @jamilibrahimli190
    @jamilibrahimli190 11 місяців тому

    Thank you so much , i was realy confused when read the docs , but now it's clear much more better!

  • @tigerfanxiao
    @tigerfanxiao 2 місяці тому

    Great explaination

  • @CodingWithDapo
    @CodingWithDapo Рік тому

    Thank you so much, I have wasted so much time searching for this simple answer.

  • @buildervision7082
    @buildervision7082 4 місяці тому

    awesome I now understand . Thanks for the explanation. i'm looking forward to watching more of your videos

  • @IdeaOrbit
    @IdeaOrbit Рік тому +1

    Great explanation 👏

  • @chamalsena
    @chamalsena 9 місяців тому

    Loved this series man !!
    btw whats the vscode theme ?

  • @victortislenko7279
    @victortislenko7279 8 місяців тому

    The best explanation! Thank you

  • @rushikeshjadhav7748
    @rushikeshjadhav7748 Рік тому

    Hats off to you sir! Great explanation for a beginner like me

  • @saschagobbels2177
    @saschagobbels2177 Рік тому

    absolutely great explanation ! thx my friend

  • @OmG21097
    @OmG21097 11 місяців тому

    Thanks for detailed explanation!!

  • @KalebMikiyas
    @KalebMikiyas Рік тому

    Best explanation 🎉

  • @suhud-al-yeqeen
    @suhud-al-yeqeen Місяць тому

    Many thanks Bro

  • @محمد-م5ث1ش
    @محمد-م5ث1ش Рік тому

    now I cant forget this, tq!

  • @nowarm
    @nowarm 6 місяців тому

    love your explanation!

  • @nodnik7
    @nodnik7 Рік тому

    Ho Wow. at 6 min it clear my mind.
    awesome, thanks.

  • @swarnakadeepashan5277
    @swarnakadeepashan5277 26 днів тому

    Thank you !

  • @pp-studio
    @pp-studio 9 місяців тому

    Thank you so much for your incredible explained for react hook. it 's make me supper clear. 🥰

  • @samuelerbo
    @samuelerbo Рік тому

    Thanks man! I learned a lot.

  • @mohit6847
    @mohit6847 Рік тому

    Thanks for the video, it was a good explanation.

  • @lhommeunknown3985
    @lhommeunknown3985 Рік тому

    Great video man, really clear explanations !

  • @leebobtheblob87
    @leebobtheblob87 Рік тому

    6:52 UseRef vs useState : triggers render?
    8:29
    Using ref on element
    Etc:
    - hooks runs after render

  • @RihaLV
    @RihaLV 8 місяців тому

    Bro great explanation. Thanks

  • @bofletcher444
    @bofletcher444 Місяць тому

    Thank you.

  • @tariksadkhi3820
    @tariksadkhi3820 9 місяців тому

    Good explanation, thanks

  • @suhaibsaifan7163
    @suhaibsaifan7163 Рік тому

    Great explanation! .Looking forward for more series

  • @mrunphotography
    @mrunphotography 10 місяців тому

    I really enjoyed it and understood

  • @milindkhadse556
    @milindkhadse556 8 місяців тому

    Helpful information thank you

  • @FGA-47
    @FGA-47 Рік тому

    Thanks that was really helpful❤🫡

  • @asifmondal7609
    @asifmondal7609 Рік тому

    Well explained buddy.. Big 👍

  • @esraamohamed5601
    @esraamohamed5601 Рік тому

    Keep doing the best work.

  • @petrus2746
    @petrus2746 11 місяців тому

    Nicely done my man.

  • @ahmednabeel358
    @ahmednabeel358 Рік тому

    You will be famous one day keep going 🙂 thanks a lot

  • @samahgad241
    @samahgad241 Рік тому

    Realy, thanks alot😍

  • @dejandjosic1258
    @dejandjosic1258 Рік тому

    Very well explained. Subscribed.

  • @alisaadati8006
    @alisaadati8006 4 місяці тому

    thanks for the video

  • @prafullkumar6369
    @prafullkumar6369 9 місяців тому

    Very nice explained

  • @maheshranjankar2127
    @maheshranjankar2127 Рік тому

    i love this man 🙏🎉

  • @idfk2873
    @idfk2873 Рік тому

    its very healful..great Video

  • @ajays3914
    @ajays3914 Рік тому

    Awesome video brother 😎

  • @mostinho7
    @mostinho7 11 місяців тому +5

    useRef stores state that doesn’t trigger a rerender when it changes. The useRef value isn’t used in the jsx component
    2:45 nuance about setState, when you call setState to set a new state value, that state variable which will not have the same value until the next render, but incrementing a useRef value is immediate, happens right away not in the next render because useRef doesn’t even trigger a rerender
    8:20 so usually you don’t use useRef value in the jsx because your component won’t rerender to display the latest useRef value, but you can use useRef to hold reference to HTMLElement to access dom elements directly and call functions on them like focusing a component

  • @chadaramprasanna9259
    @chadaramprasanna9259 11 місяців тому

    Thanks bro. 💯

  • @rubyc7771
    @rubyc7771 9 місяців тому

    To elaborate 2:24 useRef() always returns an object with one 1 property, literally 1 called 'current'. If you console.log(ref), you will see this and 'current' is of 'any' type.

  • @wintersol9921
    @wintersol9921 11 місяців тому

    This video not only made me understand useRef better, you just made me realize how react re-renders work :D Thanks man.

  • @AhammedShaheedhudheen
    @AhammedShaheedhudheen Рік тому

    you Earned a subscription

  • @sankalpsharma3050
    @sankalpsharma3050 11 місяців тому

    Thanks Cosden . Good video

  • @rennjaysoterio2543
    @rennjaysoterio2543 Рік тому

    Great explanation!

  • @andrewdatar9880
    @andrewdatar9880 Рік тому

    Your reach hooks playlist is awesome. Thank you. As for useRef vs useState - I understand the point you are trying to show. But you kinda comparing apples to oranges. If you make your state object (to be similar to ref shape) - then they are exactly the same, and state is updated in current render too, just like ref!
    const [count, setCount] = useState({value: 0});
    // click
    count.value++;
    setCount({ value: count.value });
    countRef.current++;
    console.log(count.value, countRef.current); // both are 1 after first click!
    or even simpler. Just do to the count what you do to the current:
    let [count, setCount] = useState(0);
    // click
    count++;
    setCount(count);
    countRef.current++;
    console.log(count, countRef.current); // both are 1 after first click!

    • @cosdensolutions
      @cosdensolutions  Рік тому +1

      Sure they might behave the same, but updating state like that won't trigger a re-render of the component so you don't want to do that. If you do then use a ref because that's what it's for. I think the explanation made sense because yes they are different, but serve different purposes

    • @andrewdatar9880
      @andrewdatar9880 Рік тому

      @@cosdensolutionsSure, your explanation makes perfect sense. It's react API that is too complex and requires explanations like this. And it allows to be misused like in my made up example, and yet it still re-renders and works properly. Even though in my example value of count is changed instantly (just like ref) and not in next re-render. And, yes, it triggers re-render.

  • @bctvizag
    @bctvizag 2 місяці тому

    best explained

  • @fatemeh-azad
    @fatemeh-azad 9 місяців тому

    Thanks man this is awsome

  • @supplyuniquenotessun4562
    @supplyuniquenotessun4562 Рік тому

    respected .. very thanks

  • @akankshagunti5301
    @akankshagunti5301 11 місяців тому

    Loved it 💌

  • @jay-kv6wn
    @jay-kv6wn Рік тому

    Great video as always