Тёмный

Learn useRef in 11 Minutes 

Web Dev Simplified
Подписаться 1,6 млн
Просмотров 615 тыс.
50% 1

🚨 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

Опубликовано:

 

8 июн 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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 8 месяцев назад
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.
@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
@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!!!
@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.
@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!
@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.
@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!
@sakshichoudhary7842
@sakshichoudhary7842 3 года назад
Finally understood Refs properly.. You are a saviour❤️
@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 :)))
@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
@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!!!
@nazarabdurakhimov2859
@nazarabdurakhimov2859 Год назад
Hey Kyle, I'm watching some paid React course, but when something is unclear, I open RU-vid 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!
@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.
@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.
@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
@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.
@jackmiller2518
@jackmiller2518 Год назад
Straight forward, Perfectly explained with no bs, thanks a lot!
@raffibags
@raffibags 3 года назад
By far the best explanation of the useRefs hook I've seen. Well done.
@tejasmuthya4492
@tejasmuthya4492 Год назад
GOD BLESS YOU! I have a React interview tomorrow and feel very confident after watching your useMemo, useCallback and useRef videos!
@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.
@IvinAustan
@IvinAustan 9 месяцев назад
Really had a great experience of knowing all the react hooks use cases. You did a very good job. Kudos, man!!!
@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.
@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
@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
@sam12345393
@sam12345393 2 года назад
Awesome explanation dude, I hardly comment on tech tuts, you are just so eloquent and precise. Keep up the good work!
@lpaddikt
@lpaddikt 2 года назад
Your videos are always such great content and really like how you make it concise. Awesome job man!
@user-fg6ng7ej6w
@user-fg6ng7ej6w Год назад
this playlist is very helpful: clearly explained, yet complete and concise. thanks.
@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.
@motilimkayes1352
@motilimkayes1352 3 года назад
Wow, thanks man, I'm going to re-watch this playlist every week or so for some time.
@KamilHussainShaikh
@KamilHussainShaikh 2 года назад
The quality of your presentation is appreciated. Thank you for the videos. May Allah reward you for your efforts.
@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
@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.
@mtsurov
@mtsurov Год назад
Best 10 minutes I've spent today.
@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
@teletoby94
@teletoby94 Год назад
Thank you for the concise and easy to understand explainer. Love this and appreciate your work.
@Rodo1802
@Rodo1802 7 месяцев назад
I love you, Kyle! You’ve made my React Day with this video. 🙏🏼 thank you!
@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
@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
@rayanfernandes2631
@rayanfernandes2631 3 года назад
Clear cut explanation ... Thanks kyle.. You are amazing person.
@khgriffi
@khgriffi 3 года назад
Excellent tutorial on refs! Just what I needed.
@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. 😲😲
@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..
@atheerapeter5174
@atheerapeter5174 3 года назад
I was wondering about how to grab elements in react and this golden video popped up so thank you so much
@anilsuyal
@anilsuyal 18 дней назад
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
@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
@georgimihov2690
@georgimihov2690 3 года назад
Thank you for all the amazing videos. Always very accessible and to the point.
@adammescher
@adammescher Год назад
Magnificent explanation. Thank you!
@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
@abrahamgeorge7466
@abrahamgeorge7466 2 месяца назад
Very high quality content.After watching many useRef videos ,i only understood from your video.
@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.
@0x0abb
@0x0abb 2 года назад
Web Dev Simplified is so awesome - I agree -one must show gratitude - great work!
@jesusidev
@jesusidev 4 года назад
Great video. Forward ref is another good one since we build components and share those.
@LongBoy.0
@LongBoy.0 3 года назад
Finally an amazing explainer on useRef. Thanks!
@HarshKapadia
@HarshKapadia 3 года назад
Really nice video! Thank you for (purposely) making those errors, they really helped me understand things.
@kingkesylo8516
@kingkesylo8516 4 года назад
Thanks very much for your videos. all the hooks you explained really makes sense to me now so thanks Mann
@cobaltninjas
@cobaltninjas Год назад
I honestly never thought of using useRef for anything other than DOM elements. This is brilliant.
@ambrozykleks626
@ambrozykleks626 Год назад
Great stuff, sir. Never thought about Ref that way.
@tarekghosn3648
@tarekghosn3648 Год назад
thanks i look forward to my project finishing and being able to say your videos were abig part of it
@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.
@jayantakumarroy543
@jayantakumarroy543 2 года назад
I really like the calm voice without super hyped energy,coz that's what i need for an educational video
@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
@natnaelsisay1424
@natnaelsisay1424 3 года назад
No words, Just Thank you brother
@mpilodlamini8407
@mpilodlamini8407 2 года назад
Massive respect to you thanks for these hooks tutorials. I am hooked no pun intended. Thank you.
@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!
@yusufaltundal3482
@yusufaltundal3482 Год назад
Thank you for this beautiful explanation.
@williamdaghouz
@williamdaghouz 4 года назад
Your explanations are really great!
@durgaprasaddas6494
@durgaprasaddas6494 2 года назад
Man!! this is the most informative and well explained.
@Skalexsong
@Skalexsong 2 года назад
Another great videos that I missed. Thank you !
@dimitmoto1716
@dimitmoto1716 Год назад
Everything clear! Thanks a lot!
@ascourter
@ascourter Год назад
Great video. Very clearly explained. Thank you!
@juanignaciodominguez5902
@juanignaciodominguez5902 2 года назад
You really simplified my life. Thank you!
@wichaisawangpongkasame9237
@wichaisawangpongkasame9237 2 года назад
Great explanation and warning. Thanks.
@raghavsingh5592
@raghavsingh5592 2 года назад
You solved the problem for which I sat for hours. Thank you very much.
@dustindurden3090
@dustindurden3090 3 года назад
Your content is absolutely amazing. Thank you so much for putting out this helpful Information
@devidasa9637
@devidasa9637 3 года назад
Excellent series of videos..bravo!
@karthickr1994
@karthickr1994 3 года назад
This guy deserves a like. Impressive mate. Thank you.
@saranshmehra8577
@saranshmehra8577 2 года назад
I somehow stumbled upon this video... Amazing Content.!! just wow!!. If you wanna learn refs then this is the ultimate source.
@AadeshKulkarni
@AadeshKulkarni Год назад
Beautifully explained!!
@amitborkar2892
@amitborkar2892 4 года назад
You really explained it in an easy way mate. Could you also make a video on React-router?
@FL4M3M4K3R
@FL4M3M4K3R Год назад
perfect explanation, so i dont need any more videos about topic. Its high level, thank you Kyle ;)
@andreranulfo-dev8607
@andreranulfo-dev8607 Год назад
So happy to see this Channel almost reaching 1MI subscribers.
@dmytro-skh
@dmytro-skh Год назад
it is really surprising how good you are at explanations
@MusTarIzCyx
@MusTarIzCyx 3 года назад
Brilliant explanation, thank you very much!
@fluntimes
@fluntimes 2 года назад
The. Best. Explanation. Of. useRef. On. The. Internet!
@evergreen7781
@evergreen7781 2 года назад
I think you have the best videos for react hooks on RU-vid
@micaeldie8584
@micaeldie8584 2 года назад
You blow my mind best video ever! keep the great job
@soorya3562
@soorya3562 3 года назад
Best explanation for useRef. Keep the goo work brother !
@fmaciel2
@fmaciel2 Год назад
Great tutorial! As usual, by the way. Thanks a lot!
@filip23128
@filip23128 2 года назад
Great explanation, thanks!
@fatemehzareie5423
@fatemehzareie5423 Год назад
I finally understand "useRef" thank u 😍😍✌️✌️
@julien2057
@julien2057 3 года назад
Crystal clear. Good job.
@petarkolev6928
@petarkolev6928 2 года назад
Extremely useful video!!! Thank you so much, Kyle!!!
@osamapervezriar387
@osamapervezriar387 Год назад
As always liking the video before actually watching it because i know the explanation is going to be amazing anyway! thanks Bro!!
@zxph
@zxph Год назад
Amazing. Thank you so much, Kyle!
@yassinerassy6840
@yassinerassy6840 3 года назад
thank you for your amazing explanation and useful real cases study !
@abishekbaiju1705
@abishekbaiju1705 10 месяцев назад
Thanks for the great explanation.
Далее
Learn useContext In 13 Minutes
13:08
Просмотров 691 тыс.
Top 6 React Hook Mistakes Beginners Make
21:18
Просмотров 558 тыс.
Пробую торты
00:43
Просмотров 352 тыс.
надувательство чистой воды
00:28
Learn useMemo In 10 Minutes
10:42
Просмотров 462 тыс.
Learn DOM Manipulation In 18 Minutes
18:37
Просмотров 1 млн
useRef hook in reactjs | Easiest way
19:44
Просмотров 71 тыс.
Learn useReducer In 20 Minutes
20:12
Просмотров 487 тыс.
Learn useEffect In 13 Minutes
13:38
Просмотров 807 тыс.
Never Forget React forwardRef Again
9:33
Просмотров 12 тыс.