React Hook useRef and forwarding refs with forwardRef

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024
  • useRef Hook and forwardRef to pass reference to a reactjs Component. To access html element and focus() Forwarding refs to DOM components
    #react #useRef #forwardRef
    Help the channel via patron and buying merchandise
    * / techsith
    * teespring.com/...
    Follow me for technology updates
    * / techsith
    * / techsith
    * / techsith1
    * / 13677140
    * / patelhemil
    Help me translate this video.
    * www.youtube.com...
    Note: use translate.goog... to translate this video to your language. Let me know once you do that so i can give you credit. Thank you in advance.

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

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

    You just made me a heroine on my internship program 🤩 Yeaeaaah, thank you!

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

    Was looking for a quick review of refs in React using hooks, and this video was exactly that. Well done :)

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

      Same here! This video is a really good way to learn about the refs :)

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

    A quick and precise intro to why forward ref is needed.

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

    Wow Techsith is good. Wish I had stumbled in him first in learning React Hooks....a lot of hours spent watching people try poorly rehash the examples/explanations on the Reactjs homepage. Love Techsith!!

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

    this is one of the best developers I have ever accounted in my career.
    I learn class and functional component for free here.
    I learn about javascript advance concept like closure , oop and etc.
    I prepared for my mid-level React position
    thanks techsit.
    God bless you.

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

    I am so happy ... I just arrived at the point I found out you can't give ref's to function components.... but now I can. :-)
    Thanks

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

    Nice tutorial, direct to the point and well explained. A relief after hours of frustrated research. Thank you.

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

    Thank you for clarifying 👍🏼

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

    Awesome. I've just been passing the ref down as a prop because I didn't know any better, but I'm thinking this would work so much better. Thank you!

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

    Thx for the tutorial now i understood why we need ref and forwarding ref

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

    A clean video again from you sith... thank you

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

    waiting for the perfect one and this arrives!

  • @ShubhamMishra-mz4zw
    @ShubhamMishra-mz4zw ปีที่แล้ว

    Thank you so much. This is probably the best explanation on useRef and forwardRef

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

    The best explanation of forwardRef that I found. Thanks a lot!

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

    Well explained. Thank you

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

    Best explanation out of four, I watched so far.

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

    explained clearly. It is really helpful.
    Thank you

  • @ahlambeyoud1709
    @ahlambeyoud1709 4 ปีที่แล้ว

    techsith, you deserve millions of subscribers!! always clear and comprehensive tutorials...keep up the great work you do we truly appreciate it.

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

      Thank you so much 😀 Keep on learning!

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

    keep on sith. you are doing nice work

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

    You helped me a lot I have been facing a issue with ref for weeks now, but it just that I had ref in the the first argument in the object destructive and not in the second argument

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

    Thank you soo much for this video Hemil., Finally, it's your video that makes my day.

  • @alex-front-end
    @alex-front-end 5 ปีที่แล้ว +3

    Awesome as usual. Cheers!

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

    Great video thanks very much !

  • @JaneDoe-ui2bj
    @JaneDoe-ui2bj 2 ปีที่แล้ว

    this video was sooooo helpful.. I was stuck on the child component ref for hours.. :) -- thank you!!!!!!!

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

    thank you so much. very clear and intuitive way of teaching

  • @J-ko8ig
    @J-ko8ig 4 ปีที่แล้ว

    Helped me a lot .. thank you 👍

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

    thanks! taught me exactly what I wanted :)

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

    Nice video!

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

    Brilliant! Thank you

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

    thanks this was a great video!

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

    Excellent example thank you sir!

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

    Nice one! just in time...

  • @rajshrishrimal2653
    @rajshrishrimal2653 4 ปีที่แล้ว

    Superb video 💥💥💥

  • @rtorcato
    @rtorcato 4 ปีที่แล้ว

    when you click or keydown the event that is passed contains a reference called current target. No need to use refs for forms. To set focus for first element in form you can use ref.

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

    Best on Refs.

  • @krishnayallapanthula
    @krishnayallapanthula 5 ปีที่แล้ว

    you explained it very well..

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

    Great video!!

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

    Really useful, thanks so much.

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

    Thanks, it's very helpfull

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

    Clear explanation, thanks!

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

      Pawel, Glad it was helpful!

  • @daemperador123
    @daemperador123 4 ปีที่แล้ว

    Thank you, your video helped me a lot

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

    Thank you.

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

    Just a little bit more context around forward ref in practice side would have been great... Otherwise its awesome

  • @Fatima-ie5kj
    @Fatima-ie5kj 3 ปีที่แล้ว

    nice - thankyou

  • @kirancm5165
    @kirancm5165 4 ปีที่แล้ว

    Best Explained

  • @nanasarathi
    @nanasarathi 5 ปีที่แล้ว

    Awesome... Well explained... Thanks

    • @Techsithtube
      @Techsithtube  5 ปีที่แล้ว

      Thanks for watching Narendra.

  • @Seacrest.
    @Seacrest. 3 ปีที่แล้ว

    thank you

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

    awesome

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

    thank you alot

  • @brenocristovaorocha
    @brenocristovaorocha 4 ปีที่แล้ว

    very good!

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

    Superman 🥰

  • @goffredo81
    @goffredo81 5 ปีที่แล้ว

    Nice video, how would you implement the focus based on the length of the text and not on the key event? Thank you.

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

    I don't really get the point of forwardRef since you can simply pass ref using different property name, eg. myRef and you don't really need no fancy forwardRef for that.

  • @mi-2453
    @mi-2453 4 ปีที่แล้ว

    Thank you very much..

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

    You made this so simple, thank you so much

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

    You have an accessibility issue here. Hitting enter on a form field is expected to submit the form, NOT proceed to the next field. This is a good tutorial on useRef, but it is incorrect in terms of accessibility.
    You can learn more in the MDN docs.

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

    thanks so much
    do we need to learn class component again because I am building all my application with hooks and I was wondering if I might get asked about class component at my upcoming interview
    just curious to know what yoiu think since I learnt class and hook from your channel
    thanks
    I look forward to hearing from you back.

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

    Can you bother a little to make a vedio on how to send refs from child to parent , it will be appreciated a lot .

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

    Hemil,
    Can you do a short video on Higher Order Components that uses only function components

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

      Most developers like render props & custom hooks instead hoc because it's hard to track code when using hoc

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

    which vscode theme did you use in these video?

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

    Why did it fail when we pass the refs through usual props to the child component?
    Why do we need forwardRef instead of passing it as usual props?.
    Any specific reasons for that??

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

    Anyway to make this work with Typescript? the Input has type conflicts with what React.forwardRef() expects as an argument

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

    is there possible way to explain to forwardRef when you have a dynamic list and you want to target the child component to change some property when an event is triggered

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

    What if you have huge form, with multiple inputs, what is the best practice create useRef and functions for each element, that does not seem practical, any ideas?

  • @sumeetprajapati15
    @sumeetprajapati15 5 ปีที่แล้ว

    Please share your views on, what's the future of php with javascript growing so rapidly.

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

      these days , php is used for smaller sites , but for any thing enterprise level , its usually something else. JavaScript is growing more and more.

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

    11:47 forwarded ref

  • @bhushanjagtap7382
    @bhushanjagtap7382 4 ปีที่แล้ว

    Thanks..

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

    here we are exporting forwardInput from input.js file but in app.js we are importing input not forwardInput how is this working

  • @azharponani
    @azharponani 4 ปีที่แล้ว

    Hi
    What abt using multiple refs for the same element or component...
    Like one for local use within the component.. And other for forwarding to the parent component?
    Is this possible?

  • @cody._.--._.--.
    @cody._.--._.--. 4 ปีที่แล้ว

    I saw another video that says useRef just holds any value you want whether it be an object or number or whatever. How is that different than useState? Could you store the field ref in state? On the field: ref=>{(ref) => {setMyRefs( ... spread stuff, myRefs.firstName: ref, next state blah )}}.

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

      When update a state value, the component re-renders. When you update a ref value, it doesn't trigger a re-render.

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

    Hi sir, I have a case where i used connect method from redux and made a component with React.forwardRef and at the same time i made this component connected to store via this connect method and when i pass a ref to this component actually im unable to access that ref, i know its kinda HOC and how to get that ref from connect ?

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

    Just noticed a simple thing, could you have done one function for the onKeyDown handlers, and pass the ref as a parameter?
    Then in the function, just do a switch on the param! You wouldn't have to rewrite the same function three times !!

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

      Maybe he did it so it would be obvious to viewers. Tutorials do not need to follow DRY principles to explain things like this

  • @TusharBorawake
    @TusharBorawake 4 ปีที่แล้ว

    Hi,
    Can you please make video in which parent component can have access it's child component and grandchild component methods. I was stuck in my real time project.
    Using react hooks and class component.

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

      Tushar , I do have a video on component communication which explains just that. Its using classes but the concept should be the same.

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

    What if the function Input was within the App.js file?? How can you export without using export default??

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

      you dont always have to use export default. you can simply use export but in that case you have to have import using "import { module } from " syntax

  • @singlebw4065
    @singlebw4065 4 ปีที่แล้ว

    stepBelow = (e, numInp) => {

    let count = 0;
    if(e.key === 'Enter'){
    for (let i of e.currentTarget) {
    count++;
    if (i.name === e.target.name) {
    if (count < numInp) break;
    else count = 0;
    }
    }
    e.currentTarget[count].focus()
    }
    }

  • @CameronWilby
    @CameronWilby 4 ปีที่แล้ว

    Great job, thank you!

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

    Hi, I am using
    this.props.history.push({
    pathname:`some path`,
    state:{ object :object}
    }) ;
    on handleSubmit click
    And reading the data into routed component like
    this.props.location.state.objectName.field
    This is working fine when I am using BrowserRouter even when i refresh the page i get the values on page BUT when I am using Hashrouter and I refresh the page I get error saying
    Can not read properties of undefined
    Please help

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

      HashRouter doesnt support certain things . I would suggest using BrowserRouter instead

  • @muscaiu
    @muscaiu 4 ปีที่แล้ว

    What if i want to pass ref from a hoc to a Component?

  • @egilmorstu
    @egilmorstu 4 ปีที่แล้ว

    what vs code extension that convert => into arrow?

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

    50/5000
    Why couldn't it be done that way?:
    ...
    return(
    )
    and inside Input:
    const Input=({firstNameRef)=>{

  • @shibnathroy106
    @shibnathroy106 5 ปีที่แล้ว

    Sir Love your content.
    *Video Request :* Can you please make a video on your youtube journey and how it has changed your life? I am not asking about financial gains. The positive changes that happened in your life for example opportunities, etc.
    Thank You.

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

    5:30

  • @maheshveez627
    @maheshveez627 5 ปีที่แล้ว

    Could you make a udemy a course on MERN stack

    • @Techsithtube
      @Techsithtube  5 ปีที่แล้ว

      Next week i am releasing a course on React Hooks. I might go for MERN stack afterwards.

    • @maheshveez627
      @maheshveez627 5 ปีที่แล้ว

      @@Techsithtube Thank you sir

  • @hariharanb201
    @hariharanb201 4 ปีที่แล้ว

    How can we do multilevel "forwarding ref" Parent

    • @nikolay.kupstas
      @nikolay.kupstas 4 ปีที่แล้ว +2

      Just pass this ref to your SubChild

  • @ashishmangla221
    @ashishmangla221 4 ปีที่แล้ว

    why my page got refresh on enter ?

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

      Share your code. it should not have refreshed.

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

    1000th like

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

    techshitt

  • @animanoir
    @animanoir 4 ปีที่แล้ว

    rip my ears.

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

    {2024-03-22}

  • @kamleshkumar-vm8cj
    @kamleshkumar-vm8cj 3 ปีที่แล้ว

    Not given a deep concept.. only he focused on English spoken language

  • @nishantnimish7825
    @nishantnimish7825 4 ปีที่แล้ว

    forwardRef explanation was not good