Learn React Hooks: useRef - Simply Explained!

Поделиться
HTML-код
  • Опубликовано: 1 фев 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

  • @psychobuddha5379
    @psychobuddha5379 Год назад +16

    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.

  • @davidkurniawan1358
    @davidkurniawan1358 Год назад +34

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

  • @TheGr33k13
    @TheGr33k13 Год назад +18

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

  • @dirtysouth3291
    @dirtysouth3291 Год назад +34

    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

  • @Pernicuz
    @Pernicuz Год назад +3

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

  • @a1x45h
    @a1x45h Год назад +5

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

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

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

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

  • @nirajkc224
    @nirajkc224 2 месяца назад

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

  • @ZahidHussain-hj2dk
    @ZahidHussain-hj2dk Год назад +3

    Best useref tutorial.....highly recommended

  • @SK-fq2yz
    @SK-fq2yz Год назад +1

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

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

  • @ManishGupta-nv5by
    @ManishGupta-nv5by 2 месяца назад

    i always found your tutorial professional without any waste.

  • @es7729
    @es7729 10 месяцев назад

    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"?

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

  • @ofek_x
    @ofek_x 2 месяца назад

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

  • @Engr.SharoonHoney
    @Engr.SharoonHoney 8 месяцев назад

    That's amazing explanation of useRef on whole RUclips. Thanks sir 👍

  • @benihahitti3513
    @benihahitti3513 6 месяцев назад

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

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

  • @pranavjaiswal2379
    @pranavjaiswal2379 Год назад

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

  • @kasiakordys266
    @kasiakordys266 Год назад

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

  • @julienheng3880
    @julienheng3880 Год назад

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

  • @melikarazavi3599
    @melikarazavi3599 Год назад

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

  • @핑구-s3g
    @핑구-s3g 6 месяцев назад

    Amazing, I enjoy watching your React lectures!

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

  • @HamzaAhmad-e2x
    @HamzaAhmad-e2x Год назад +2

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

  • @cheiguerabdelwehab6802
    @cheiguerabdelwehab6802 Год назад

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

  • @srsh12345
    @srsh12345 3 месяца назад

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

  • @jamilibrahimli190
    @jamilibrahimli190 11 месяцев назад

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

  • @a_maxed_out_handle_of_30_chars
    @a_maxed_out_handle_of_30_chars Год назад +2

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

  • @adrianayon5513
    @adrianayon5513 Год назад +2

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

  • @woodzeppelin3241
    @woodzeppelin3241 4 месяца назад

    A really good deep dive on hooks for me. Thanks

  • @CodingWithDapo
    @CodingWithDapo Год назад

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

  • @zambidzhelov6734
    @zambidzhelov6734 Год назад

    This is the best useRef tutorial . Thansk !

  • @vesa95
    @vesa95 Год назад +3

    Love this series!!! 🤗

  • @buildervision7082
    @buildervision7082 5 месяцев назад

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

  • @altan183
    @altan183 11 месяцев назад

    Very clear and concise, thank you for the explanation.

  • @vincetamayo9669
    @vincetamayo9669 11 месяцев назад

    very clear and concise tutorial. thanks for this content

  • @dhruvdonsahu9972
    @dhruvdonsahu9972 21 день назад

    thanks buddy, a pretty good video keep it up!

  • @baciusebastian6361
    @baciusebastian6361 Год назад +1

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

  • @wintersol9921
    @wintersol9921 Год назад

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

  • @mostinho7
    @mostinho7 Год назад +6

    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

  • @prithuadhikary720
    @prithuadhikary720 4 месяца назад

    Great explanation. Thanks!

  • @KrishanMalinda-z9i
    @KrishanMalinda-z9i 2 месяца назад

    It's really understandable. Thank you ❤

  • @arushraj3807
    @arushraj3807 5 месяцев назад

    Amazing explanation 🎉

  • @ahmednabeel358
    @ahmednabeel358 Год назад

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

  • @KyawMyo
    @KyawMyo Месяц назад

    really nice explanation. thanks a lot.

  • @suhaibsaifan7163
    @suhaibsaifan7163 Год назад

    Great explanation! .Looking forward for more series

  • @chamalsena
    @chamalsena 9 месяцев назад

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

  • @rushikeshjadhav7748
    @rushikeshjadhav7748 Год назад

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

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

  • @lhommeunknown3985
    @lhommeunknown3985 Год назад

    Great video man, really clear explanations !

  • @syuo5051
    @syuo5051 8 месяцев назад

    Many thanks for this clear explanation. 💗💗

  • @saschagobbels2177
    @saschagobbels2177 Год назад

    absolutely great explanation ! thx my friend

  • @victortislenko7279
    @victortislenko7279 9 месяцев назад

    The best explanation! Thank you

  • @alexdsr1
    @alexdsr1 8 месяцев назад

    This a good explanation of useRef.
    However, there is an issue when using it when Concurrent Mode is activated in React.
    That's a topic that is even more complex in regards to the usage of useRef.
    I don't know if you can make a video on but it would help people who are going to run into that issue sooner or later. Thanks

  • @alejandroluisacosta2164
    @alejandroluisacosta2164 4 месяца назад

    Nice example. Thanks

  • @blackfortmusic7729
    @blackfortmusic7729 Год назад

    Growing fast man!

  • @IdeaOrbit
    @IdeaOrbit Год назад +1

    Great explanation 👏

  • @TuneTrekMusics
    @TuneTrekMusics Месяц назад

    Thank you brother go ahead👍🏻👍🏻

  • @ajays3914
    @ajays3914 Год назад

    Awesome video brother 😎

  • @petrus2746
    @petrus2746 Год назад

    Nicely done my man.

  • @OmG21097
    @OmG21097 Год назад

    Thanks for detailed explanation!!

  • @eliyahutarab4862
    @eliyahutarab4862 Год назад +1

    Clear and simple thank you

  • @tigerfanxiao
    @tigerfanxiao 3 месяца назад

    Great explaination

  • @rubyc7771
    @rubyc7771 10 месяцев назад

    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.

  • @esraamohamed5601
    @esraamohamed5601 Год назад

    Keep doing the best work.

  • @samuelerbo
    @samuelerbo Год назад

    Thanks man! I learned a lot.

  • @محمد-م5ث1ش
    @محمد-م5ث1ش Год назад

    now I cant forget this, tq!

  • @asifmondal7609
    @asifmondal7609 Год назад

    Well explained buddy.. Big 👍

  • @leebobtheblob87
    @leebobtheblob87 Год назад

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

  • @nowarm
    @nowarm 7 месяцев назад

    love your explanation!

  • @dejandjosic1258
    @dejandjosic1258 Год назад

    Very well explained. Subscribed.

  • @nodnik7
    @nodnik7 Год назад

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

  • @pp-studio
    @pp-studio 10 месяцев назад

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

  • @RihaLV
    @RihaLV 9 месяцев назад

    Bro great explanation. Thanks

  • @mohit6847
    @mohit6847 Год назад

    Thanks for the video, it was a good explanation.

  • @KalebMikiyas
    @KalebMikiyas Год назад

    Best explanation 🎉

  • @lakshmis5860
    @lakshmis5860 6 месяцев назад

    Pls do a series on react beginners completing all concepts

  • @sankalpsharma3050
    @sankalpsharma3050 Год назад

    Thanks Cosden . Good video

  • @tariksadkhi3820
    @tariksadkhi3820 10 месяцев назад

    Good explanation, thanks

  • @prafullkumar6369
    @prafullkumar6369 9 месяцев назад

    Very nice explained

  • @AhammedShaheedhudheen
    @AhammedShaheedhudheen Год назад

    you Earned a subscription

  • @jay-kv6wn
    @jay-kv6wn Год назад

    Great video as always

  • @saadchraibi6712
    @saadchraibi6712 Год назад

    Awesome, straight to the point!
    Could you make a video about custom Hooks?

    • @cosdensolutions
      @cosdensolutions  Год назад +1

      Already have ☺️

    • @saadchraibi6712
      @saadchraibi6712 Год назад

      @@cosdensolutions would you mind sharing the link? I can’t find it

    • @cosdensolutions
      @cosdensolutions  Год назад

      @@saadchraibi6712 check my channel -> playlists -> custom hooks (there's only one video but there will be more)

  • @mrunphotography
    @mrunphotography 11 месяцев назад

    I really enjoyed it and understood

  • @idfk2873
    @idfk2873 Год назад

    its very healful..great Video

  • @swarnakadeepashan5277
    @swarnakadeepashan5277 Месяц назад

    Thank you !

  • @rennjaysoterio2543
    @rennjaysoterio2543 Год назад

    Great explanation!

  • @FGA-47
    @FGA-47 Год назад

    Thanks that was really helpful❤🫡

  • @suhud-al-yeqeen
    @suhud-al-yeqeen Месяц назад

    Many thanks Bro

  • @maheshpattar7714
    @maheshpattar7714 Месяц назад

    @codeson - That's interesting but I have one question. Add setCount and print countRef.current and count both. And when you click button, UI shows updated value for both. but countRef.current shouln't right ? If you remove setCount and click btn countRef.current then UI won't update... hows that possible ?

  • @zabialy2919
    @zabialy2919 Год назад

    Great video, keep it up

  • @TheRealMinhHoang
    @TheRealMinhHoang Год назад

    Thank you for creating an amazing tutorial, it's truly help me a lot!
    I have a request, can you make video about using useRef, forwardRef and useImperativeHandle hook in React? Component that managing it's own state. I have always wanted to know more about this react pattern.

  • @milindkhadse556
    @milindkhadse556 9 месяцев назад

    Helpful information thank you

  • @alisaadati8006
    @alisaadati8006 4 месяца назад

    thanks for the video

  • @bctvizag
    @bctvizag 3 месяца назад

    best explained