Learn useRef in 11 Minutes

  Рет қаралды 613,389

Web Dev Simplified

Web Dev Simplified

4 жыл бұрын

🚨 IMPORTANT:
Full React Course: courses.webdevsimplified.com/...
In this video I cover everything you need to know about the useRef hook. I go over all the main use cases for useRef as well as many common mistakes that developers make. This is part of a series of React videos where I cover all the important hooks in React.
📚 Materials/References:
useRef Blog Article: blog.webdevsimplified.com/202...
React Hooks Playlist: • React Hooks
🧠 Concepts Covered:
- How to use hooks in React
- How to store values between renders in React function components
- How to use the useRef hook
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
#ReactJs #WDS #useRef

Пікірлер: 599
@dhruvmaindola5767
@dhruvmaindola5767 Жыл бұрын
If anyone is still confused about the last example. Here is a simple explanation. Just keep three things in mind. 1. useState() causes re-render. 2. useRef() DOESN'T cause re-render. 3. useEffect() runs AFTER render. So the flow goes like this. name = "" prevName = "" -> Lets say you put "A" in the text field , so setName() runs. Changes the value of name = "A" to this. Component renders. -> Then useEffect is run where you set prevName to name. prevName is the same as name which is "A" but here comes the 2nd point i wrote. useRef() DOESN'T cause re-render. -> So when you changed the name , component got rendered and useEffect caused the prevName to change. But the thing is that component has already been rendered with whatever value prevName HAD before setName() got called. prevName is not STORING the previous value of name. It is only DISPLAYING the previous value of name. Hope this helps.
@omyerawar7976
@omyerawar7976 Жыл бұрын
Great Explanation 🤩
@user-zv6bv7eu8k
@user-zv6bv7eu8k 7 ай бұрын
Is it safe to say that useEffect() uses the data from the previous render ??? and I understand we store it in a useRef() since it wont cause a rerender .... but what's the difference using a useRef() variable oppose to just updating a normal variable ... NEED HELP
@waynerandom11
@waynerandom11 7 ай бұрын
@@user-zv6bv7eu8k Because if you change the declaration to be const prevName = , then prevName would be set to at the start of every re-render whereas const prevName = useRef() will set prevName to only on the first render. Subsequent renders will set prevName to the whatever the last assigned value was. Hope that helps!
@sarveshwarpandey9516
@sarveshwarpandey9516 6 ай бұрын
thanks!
@dongbinkim3773
@dongbinkim3773 4 ай бұрын
@@waynerandom11 Thanks for your great explanation!
@Gabrielito300
@Gabrielito300 4 жыл бұрын
I rarely use to comment on videos, but i think this video deserves an specific acknowledgment. It was an excellent explanation about useRef, and the way that you showed the difference between it and states is super important. I hope you keep helping us, amateur web developers, to keep improving. Hope you have a lovely weekend ❤
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Thank you so much!
@mattmarkus4868
@mattmarkus4868 2 жыл бұрын
i agree. i would like to see more advanced stuff, because he explains things very well and clearly.
@cristianouzumaki2455
@cristianouzumaki2455 3 жыл бұрын
I might purchase your course despite already knowing react. great vids bro.
@WebDevSimplified
@WebDevSimplified 3 жыл бұрын
Thank you!
@shyambhujel8797
@shyambhujel8797 3 жыл бұрын
@@WebDevSimplified c b0
@shyambhujel8797
@shyambhujel8797 3 жыл бұрын
@@WebDevSimplifiedy yyyyyyyy
@shyambhujel8797
@shyambhujel8797 3 жыл бұрын
@@WebDevSimplified hhyyt5
@siddheshb.kukade4685
@siddheshb.kukade4685 3 жыл бұрын
Lol
@elie3423
@elie3423 2 жыл бұрын
for people confused of what is happening in the last use case of useref, useEffect by definition runs after the things gets rendered. so he is basically printing the value of the useState before assigning it in the useEffect
@anandkrishnanmj95
@anandkrishnanmj95 2 жыл бұрын
Thanks for clearing that, have been looking through the comments to figure that out.😃
@anandkrishnanmj95
@anandkrishnanmj95 2 жыл бұрын
And after the render, useEffect gets called and changes the value of prevName.current to current name, And even though the prevName.current currently holds the current name after useEffect, it won't trigger a re-render And that's why the prevName.current used in the return statement prints the previousName right?
@veselinmladenov7941
@veselinmladenov7941 Жыл бұрын
Thank you for that Elie, I spent a decent time trying to understand what is going on and why is behaving that way.
@zksumon847
@zksumon847 Жыл бұрын
Thanks a lot
@marco8673
@marco8673 Жыл бұрын
thank you very much!!!
@wawayltd
@wawayltd 3 жыл бұрын
I hope this comment will help someone who can't get a grip on it like I couldn't for some time... When you are trying to understand logic of these processes explained in the video, just keep in mind one important thing - useEffect() only runs AFTER your component is rendered. Like in the last example where we trying to get previous value of our name, I would say that prevValue.current is not actually storing the value of our previous name, it displays it as component renders - then useEffect runs, prevValue.current now storing value of current name, but because useRef doesn't make component to re-render, it "keeps that in mind", but doesn't display it till the next time component is rendered. Oh gosh.. I was hoping I'll put it simple. I hope it makes sense. It took me while to figure out logic and I feel need to share it with people.
@avineshgupta6264
@avineshgupta6264 3 жыл бұрын
Thanx dude
@bikerguy3338
@bikerguy3338 Жыл бұрын
I was struggling to understand this too. Thanks for clarifying what's happening!
@balluvwdwadi8995
@balluvwdwadi8995 Жыл бұрын
Thank you!🎉
@AbhishekBhandari-om9hu
@AbhishekBhandari-om9hu Жыл бұрын
thanks
@daniillitvinenko4348
@daniillitvinenko4348 11 ай бұрын
Thank you, I was specifically looking for this in the comments
@mrarc197
@mrarc197 4 жыл бұрын
Im using most of things you teach on daily basis but I am still watching your videos and in many cases Im finding gems that I never even thought about. Good job mate, keep doing it, its good content.
@luis_soul1
@luis_soul1 3 жыл бұрын
I struggled a little bit trying to understand Ref in React and I constantly found a bunch of explanations with examples but no other like this video. It made me understand everything. Thank you so much Kyle, shout out to you for explaining Ref very simple and concise.
@sudarshankj
@sudarshankj 3 жыл бұрын
What I truly love about your videos are: They are really crisp and cover the crux of the topic magically in a very small amount of time! That takes great skill, keep it up!
@liamwelsh5565
@liamwelsh5565 Жыл бұрын
Little shortcut. Instead of doing const something = useRef(), you can use object destructoring and set it to const {current: something} = useRef(). This allows you to access your ref without needing .current.
@Tommy-x-Ray
@Tommy-x-Ray Жыл бұрын
doesn't work, because you have to set ref={something} later on
@nazarabdurakhimov2859
@nazarabdurakhimov2859 Жыл бұрын
Hey Kyle, I'm watching some paid React course, but when something is unclear, I open KZbin and specifically look for your videos - I find them super useful, you can explain difficult concepts in a clear and relaxed way. I can see how every aspect of your videos (intro, speech, explanation, examples) are thoroughly thought out. Thx a lot for all of your effort!
@sakshichoudhary7842
@sakshichoudhary7842 3 жыл бұрын
Finally understood Refs properly.. You are a saviour❤️
@exceptionalbuildingservices
@exceptionalbuildingservices 3 жыл бұрын
Mate I watched so many videos and read so many articles, but I never saw anything like yours! Short and very well explained. That's what I needed! Thanks!!!
@zain2314
@zain2314 3 жыл бұрын
bro i have been following your tutorial and none of them have failed to amaze me, your explaination is so onpoint and simple.
@starwarsfan9575
@starwarsfan9575 4 жыл бұрын
I don't get time to learn by myself because of busy work schedule but through your quick and easy videos like this one I am able to....thanks! Keep up the good work!
@balajiganesh4246
@balajiganesh4246 2 жыл бұрын
That was super useful bro. I always felt this concept was too complex and always avoided it. Now, I have a decent clartity within 10 mins. Thanks a lot
@quietcalm7299
@quietcalm7299 3 жыл бұрын
I never comment on videos but this explanation was so spot on - it helped me so much converting a tutorial that was using dom selectors into react-syntax. So thanks a lot :)))
@jackmiller2518
@jackmiller2518 Жыл бұрын
Straight forward, Perfectly explained with no bs, thanks a lot!
@alizarean5080
@alizarean5080 2 ай бұрын
after searching for about 5 hours this video finally answered all my questions. I can't thank you enough buddy. I wish you the best of bests.
@nigelbess5168
@nigelbess5168 Ай бұрын
Your content really breaks these down in a useful way. Thanks so much, youve saved me a lot of time.
@gerasmaster2099
@gerasmaster2099 Жыл бұрын
Every time I need to learn something new about JavaScript, I look for your videos. You explain everything so clear it couldn't be better
@csmnitemare4532
@csmnitemare4532 2 жыл бұрын
These vids are gold!!! thank you for helping this aspiring dev understand things that some seem to just gloss over or explain horribly.
@raffibags
@raffibags 3 жыл бұрын
By far the best explanation of the useRefs hook I've seen. Well done.
@temzeks
@temzeks 3 жыл бұрын
not gonna lie, i went through the useRef from one of the react books today, and i didnt understand what it was, this video somewhat made it brighter for me, but not entirely. Gotta rewatch it in the morning! Keep it up
@IvinAustan
@IvinAustan 9 ай бұрын
Really had a great experience of knowing all the react hooks use cases. You did a very good job. Kudos, man!!!
@tejasmuthya4492
@tejasmuthya4492 Жыл бұрын
GOD BLESS YOU! I have a React interview tomorrow and feel very confident after watching your useMemo, useCallback and useRef videos!
@franco-cespi
@franco-cespi 4 жыл бұрын
As with useMemo I thank you for thining down the difficult concepts of React. Greate examples! I can't wait to see some more hooks simplified.
@user-fg6ng7ej6w
@user-fg6ng7ej6w Жыл бұрын
this playlist is very helpful: clearly explained, yet complete and concise. thanks.
@chrtravels
@chrtravels 2 жыл бұрын
Great video. Your videos make the topics so easy to understand, thanks for that. I know enough react to get myself into trouble so looking to purchase your course to get some extra depth on the topics.
@nareshbhati7527
@nareshbhati7527 2 жыл бұрын
Thank you, you always give new knowledge. In 10 minutes you clear the concepts of 1 hour. Thank you so much for saving us a lot of time.
@lpaddikt
@lpaddikt 2 жыл бұрын
Your videos are always such great content and really like how you make it concise. Awesome job man!
@motilimkayes1352
@motilimkayes1352 3 жыл бұрын
Wow, thanks man, I'm going to re-watch this playlist every week or so for some time.
@sam12345393
@sam12345393 2 жыл бұрын
Awesome explanation dude, I hardly comment on tech tuts, you are just so eloquent and precise. Keep up the good work!
@iamnadeemzafar
@iamnadeemzafar 3 жыл бұрын
I was googling for the actual use case of useRef and after long time i got satisfied watching your video ... You told exactly what i wanted to know.... A lot of tutorial had the same caption but not worth satisfying. And the most appreciable is that you only took few minutes..
@teletoby94
@teletoby94 Жыл бұрын
Thank you for the concise and easy to understand explainer. Love this and appreciate your work.
@khgriffi
@khgriffi 3 жыл бұрын
Excellent tutorial on refs! Just what I needed.
@andrewsmichael7047
@andrewsmichael7047 Жыл бұрын
Thank you so much bro, I used to be confused about refs most times even the react docs didn't make it as clear as this video. Thanks a lot
@sleepingUgly
@sleepingUgly 2 жыл бұрын
Great video. Thank you for showing the different use cases. I had no idea that it is not in included in the lifecycles and persists data.
@anilsuyal
@anilsuyal 12 күн бұрын
Wow! what a straightforwad amazing explanation to useRef. I was tired understanding it from lot of videos and docuementation, but understood only because of you. thank you sir
@Ichigo-kurusaki580
@Ichigo-kurusaki580 2 жыл бұрын
Dude you explain such topics so good with easy examples and simple usecase that before even going anywhere else to understand some concept i made it a habit to go through your videos first. Thanks for uploading
@Rodo1802
@Rodo1802 7 ай бұрын
I love you, Kyle! You’ve made my React Day with this video. 🙏🏼 thank you!
@georgimihov2690
@georgimihov2690 3 жыл бұрын
Thank you for all the amazing videos. Always very accessible and to the point.
@wcw23085
@wcw23085 3 жыл бұрын
YOU ARE A LIFESAVER!!!! Been searching for how to reference a DOM node in React and here you are showing me what I've been looking for the WHOLE DAMN DAY. THNAK YOU!!!!!!!! AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
@rayanfernandes2631
@rayanfernandes2631 3 жыл бұрын
Clear cut explanation ... Thanks kyle.. You are amazing person.
@dimitmoto1716
@dimitmoto1716 Жыл бұрын
Everything clear! Thanks a lot!
@adammescher
@adammescher Жыл бұрын
Magnificent explanation. Thank you!
@KamilHussainShaikh
@KamilHussainShaikh 2 жыл бұрын
The quality of your presentation is appreciated. Thank you for the videos. May Allah reward you for your efforts.
@fahmidatasnimlisa2592
@fahmidatasnimlisa2592 3 жыл бұрын
I'm pulling an all-nighter and i got my final exam on React in a couple of hours. Thanks for the video, so greatly explained
@atheerapeter5174
@atheerapeter5174 3 жыл бұрын
I was wondering about how to grab elements in react and this golden video popped up so thank you so much
@williamdaghouz
@williamdaghouz 4 жыл бұрын
Your explanations are really great!
@cobaltninjas
@cobaltninjas Жыл бұрын
I honestly never thought of using useRef for anything other than DOM elements. This is brilliant.
@jesusidev
@jesusidev 4 жыл бұрын
Great video. Forward ref is another good one since we build components and share those.
@ascourter
@ascourter Жыл бұрын
Great video. Very clearly explained. Thank you!
@k.l7111
@k.l7111 Жыл бұрын
Clear comparison with useState and nice explanation of rendering lifecycle. Thank you!
@deepanshukhorwal8938
@deepanshukhorwal8938 Жыл бұрын
your content is fabulous and most useful for working professionals
@mtsurov
@mtsurov Жыл бұрын
Best 10 minutes I've spent today.
@ambrozykleks626
@ambrozykleks626 Жыл бұрын
Great stuff, sir. Never thought about Ref that way.
@chunkwanchan5503
@chunkwanchan5503 Жыл бұрын
thank you! think this hook really shed light on my mini project. I can save the previous dom state and render it back on the page now
@kingkesylo8516
@kingkesylo8516 4 жыл бұрын
Thanks very much for your videos. all the hooks you explained really makes sense to me now so thanks Mann
@tarekghosn3648
@tarekghosn3648 Жыл бұрын
thanks i look forward to my project finishing and being able to say your videos were abig part of it
@Skalexsong
@Skalexsong 2 жыл бұрын
Another great videos that I missed. Thank you !
@yusufaltundal3482
@yusufaltundal3482 Жыл бұрын
Thank you for this beautiful explanation.
@AadeshKulkarni
@AadeshKulkarni Жыл бұрын
Beautifully explained!!
@LongBoy.0
@LongBoy.0 3 жыл бұрын
Finally an amazing explainer on useRef. Thanks!
@juanignaciodominguez5902
@juanignaciodominguez5902 2 жыл бұрын
You really simplified my life. Thank you!
@wichaisawangpongkasame9237
@wichaisawangpongkasame9237 2 жыл бұрын
Great explanation and warning. Thanks.
@abrahamgeorge7466
@abrahamgeorge7466 Ай бұрын
Very high quality content.After watching many useRef videos ,i only understood from your video.
@devidasa9637
@devidasa9637 3 жыл бұрын
Excellent series of videos..bravo!
@mpilodlamini8407
@mpilodlamini8407 2 жыл бұрын
Massive respect to you thanks for these hooks tutorials. I am hooked no pun intended. Thank you.
@29rohitkumar01
@29rohitkumar01 3 жыл бұрын
It's always great to watch your video, Even if I know some topic and watch your videos, there is always something new that I get to know. Keep doing the good work brother.
@HarshKapadia
@HarshKapadia 3 жыл бұрын
Really nice video! Thank you for (purposely) making those errors, they really helped me understand things.
@b1ackbrd1
@b1ackbrd1 3 жыл бұрын
After watching this I used it in one of our Video player component and its just awesome. Thanks a lot for this video
@MusTarIzCyx
@MusTarIzCyx 3 жыл бұрын
Brilliant explanation, thank you very much!
@dustindurden3090
@dustindurden3090 3 жыл бұрын
Your content is absolutely amazing. Thank you so much for putting out this helpful Information
@aldhie33
@aldhie33 2 жыл бұрын
thank you so much. i spend two hours read the doc and it still confuse me, but with your explanation, it makes me understand the way to use this hooks. 😲😲
@durgaprasaddas6494
@durgaprasaddas6494 2 жыл бұрын
Man!! this is the most informative and well explained.
@0x0abb
@0x0abb 2 жыл бұрын
Web Dev Simplified is so awesome - I agree -one must show gratitude - great work!
@fmaciel2
@fmaciel2 Жыл бұрын
Great tutorial! As usual, by the way. Thanks a lot!
@natnaelsisay1424
@natnaelsisay1424 3 жыл бұрын
No words, Just Thank you brother
@petarkolev6928
@petarkolev6928 Жыл бұрын
Extremely useful video!!! Thank you so much, Kyle!!!
@yassinerassy6840
@yassinerassy6840 2 жыл бұрын
thank you for your amazing explanation and useful real cases study !
@zxph
@zxph Жыл бұрын
Amazing. Thank you so much, Kyle!
@julien2057
@julien2057 3 жыл бұрын
Crystal clear. Good job.
@jayantakumarroy543
@jayantakumarroy543 2 жыл бұрын
I really like the calm voice without super hyped energy,coz that's what i need for an educational video
@filip23128
@filip23128 2 жыл бұрын
Great explanation, thanks!
@skooliecaptain
@skooliecaptain 3 жыл бұрын
Absolutely saved me with this one! Thanks
@abishekbaiju1705
@abishekbaiju1705 9 ай бұрын
Thanks for the great explanation.
@atreysinainadkarni5453
@atreysinainadkarni5453 Жыл бұрын
This is really helpful, thank you.
@dmytro-skh
@dmytro-skh Жыл бұрын
it is really surprising how good you are at explanations
@karthickr1994
@karthickr1994 3 жыл бұрын
This guy deserves a like. Impressive mate. Thank you.
@FL4M3M4K3R
@FL4M3M4K3R Жыл бұрын
perfect explanation, so i dont need any more videos about topic. Its high level, thank you Kyle ;)
@viniciusalvess
@viniciusalvess 2 жыл бұрын
I had a situation where I had to read qr codes, but the qr code component triggered and event multiple times when the camera was reading the qr code because of motion and low delay tim. I couldn't increase the delay time, because it would take too long to scan many qr codes and useRef hook helped me to solve my issue. Thanks Kyle for the great video.
@micaeldie8584
@micaeldie8584 2 жыл бұрын
You blow my mind best video ever! keep the great job
@andreranulfo-dev8607
@andreranulfo-dev8607 Жыл бұрын
So happy to see this Channel almost reaching 1MI subscribers.
@sambass827
@sambass827 2 жыл бұрын
Awesome explanation!
@amitborkar2892
@amitborkar2892 4 жыл бұрын
You really explained it in an easy way mate. Could you also make a video on React-router?
@raghavsingh5592
@raghavsingh5592 2 жыл бұрын
You solved the problem for which I sat for hours. Thank you very much.
@vadimm3077
@vadimm3077 4 жыл бұрын
Cool content! Thank you so much for your knowledge sharing!!
@nextleveltech267
@nextleveltech267 2 ай бұрын
Super useful content... Thank you so much ❤️..
@miskaknapek
@miskaknapek 3 жыл бұрын
many thanks for the very clear and concise explanation! I'm not sure how you managed to do it as fluently, in one clip. ( hope you didn't need to do too many retakes ;) many thanks in any event!
@saranshmehra8577
@saranshmehra8577 2 жыл бұрын
I somehow stumbled upon this video... Amazing Content.!! just wow!!. If you wanna learn refs then this is the ultimate source.
Learn useContext In 13 Minutes
13:08
Web Dev Simplified
Рет қаралды 689 М.
03- React Hooks - useRef [ARABIC]
15:47
Nour Homsi
Рет қаралды 9 М.
Follow @karina-kola please 🙏🥺
00:21
Andrey Grechka
Рет қаралды 25 МЛН
Не пей газировку у мамы в машине
00:28
Даша Боровик
Рет қаралды 10 МЛН
[Vowel]물고기는 물에서 살아야 해🐟🤣Fish have to live in the water #funny
00:53
О, сосисочки! (Или корейская уличная еда?)
00:32
Кушать Хочу
Рет қаралды 7 МЛН
Learn useMemo In 10 Minutes
10:42
Web Dev Simplified
Рет қаралды 460 М.
What is useRef Hook in React in telugu - 51 - ReactJs in Telugu
14:57
Telugu Skillhub
Рет қаралды 32 М.
React useRef() hook introduction 🗳️
11:18
Bro Code
Рет қаралды 10 М.
React Router Tutorial - 14 - Lazy Loading
6:45
Codevolution
Рет қаралды 106 М.
React Hooks Crash Course (useMemo, useCallback and more).
31:49
developedbyed
Рет қаралды 79 М.
12 | Learn HTML | ﹤iframe﹥
2:19
Dima L
Рет қаралды 18
Follow @karina-kola please 🙏🥺
00:21
Andrey Grechka
Рет қаралды 25 МЛН