Never Forget React forwardRef Again

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • forwardRef can be confusing when moving from vanilla JavaScript. Once you think like React, however, it both makes sense and is more useful than you'd think.
    🔗 Key Links 🔗
    - Code: github.com/cod...
    - Forward Ref docs: react.dev/refe...
    ---------------------------------------
    🌐 Connect With Me 🌐
    - Website: codinginpublic...
    - Blog: chrispenningto...
    - Twitter: / cpenned
    - Patreon: / coding_in_public
    - Buy Me a Coffee: www.buymeacoff...

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

  • @alinikpey5797
    @alinikpey5797 10 หลายเดือนก่อน +11

    Watching 10 video to understand what is userRef and forwardRef and why it is called ref untill i heard the answer from you. Thank you. that was a nice explanation

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน +1

      That’s so kind! Glad it was such a help! Thanks!

  • @raldskie23
    @raldskie23 10 หลายเดือนก่อน +11

    This is the clearest explanation of forwardRef ive ever watched and learned. Just straight up to the point, with proper context to the premise. 🔥

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน

      So glad it was a help! I find that my clearest videos are the ones that come out of errors I make because it forces me to get to the bottom of why things are the way they are. Glad it was a help to you, too!

  • @prashlovessamosa
    @prashlovessamosa 10 หลายเดือนก่อน +4

    Thanks for sharing please make more react stuff.

  • @morchellemusic2829
    @morchellemusic2829 9 หลายเดือนก่อน +1

    Thanks for the explanation, very clear and concise

    • @CodinginPublic
      @CodinginPublic  9 หลายเดือนก่อน

      Glad it was helpful!

  • @godofwar8262
    @godofwar8262 10 หลายเดือนก่อน +2

    Thank you finally a react video

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน +2

      Ha :) hopefully more to come!

  • @ahmadm.hawwash3931
    @ahmadm.hawwash3931 2 หลายเดือนก่อน

    Great video, thanks for sharing!
    Can't we pass it as another prop name? I mean we could pass as reference instead of ref. Could that solve the issue?

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

    why can't we use just another variable instead of ref ? I mean, in the Form component, we pass another variable, say 'inputRefVar' whose value would be {inputRef}. now inside the component in the input element, we set ref={inputRefVar}. wouldn't it work ? we could still have the parent control it right ? why forwardRef ?

  • @sahilrathod3930
    @sahilrathod3930 9 หลายเดือนก่อน +1

    Great explanation... ❤

    • @CodinginPublic
      @CodinginPublic  9 หลายเดือนก่อน

      Thanks for saying something! Glad it was a help!

  • @__greg__
    @__greg__ 8 หลายเดือนก่อน

    This was a great explanation, thanks for sharing!

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

    Very beautifully explained! Thanks alot!

    • @CodinginPublic
      @CodinginPublic  7 หลายเดือนก่อน +1

      Glad it was helpful!

  • @osifojohn1513
    @osifojohn1513 3 หลายเดือนก่อน

    Love this video, you cleared all my doubts.

    • @CodinginPublic
      @CodinginPublic  3 หลายเดือนก่อน

      Glad it was helpful!

  • @RandomMcLain
    @RandomMcLain 10 หลายเดือนก่อน +1

    🎯 Key Takeaways for quick navigation:
    00:34 🤖 React relies on createElement to generate elements in the virtual DOM.
    02:26 🛡️ useRef helps bridge the gap between the virtual DOM and the actual DOM for direct access.
    03:22 💼 Understanding when to use forwardRef: when a component needs access to the actual DOM node, not just the virtual DOM.
    05:14 🛡️ How to implement forwardRef in JavaScript and TypeScript, passing the ref down to child components.
    08:30 🤖 Utilizing the children prop for dynamic content within a component.
    Made with HARPA AI

  • @SouravDuttaROCKSTAR
    @SouravDuttaROCKSTAR 10 หลายเดือนก่อน +4

    One of the best explanation for forwardRef. Short yet precise.💯

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน +3

      Glad it was a help! Thanks for saying something!

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

    Thanks!

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

    Thanks

  • @mohammadalrefaai4377
    @mohammadalrefaai4377 8 หลายเดือนก่อน

    Actually the form could have one responsibility it could have the form and their inputs also the behavior of the inputs, it's cleaner 😊

    • @CodinginPublic
      @CodinginPublic  8 หลายเดือนก่อน +1

      Could you explain more what you mean here?

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

    What about multiple refs. If we want to pass multiple refs than how we use forwardrefs.

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

      You don't :) The idea is to have each component as it's own standalone. So you'd have a single input with a forwardRed that you would embed in a form that might have another forwardRef, etc.

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

      Just pass refs as normal props. It works on older React versions too like 17.0.0. I don't understand why to even use fowardRef.

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt 9 หลายเดือนก่อน

    Awesome

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

    You CAN pass refs directly as props

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

      You can now in react 19. :)

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

      @@CodinginPublic Not true, you could pass refs as props before, and it just worked. I tested in on React 17.0.0. I spend some time on internet and still really didn't understand why fowardRef exists.

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

    {2024-03-22}

    • @CodinginPublic
      @CodinginPublic  6 หลายเดือนก่อน

      Paresh was here. 👋

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

    And now they ditch forwardRef :v

    • @CodinginPublic
      @CodinginPublic  5 หลายเดือนก่อน +1

      lol i know, right?

  • @ChristinaCodes
    @ChristinaCodes 10 หลายเดือนก่อน

    This is by far the best forwardRef video I’ve ever seen, it finally makes sense 🥲 Thank you so much for this.

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน +1

      You’re welcome! Glad it was such a help! That’s so…

  • @akash-kumar737
    @akash-kumar737 10 หลายเดือนก่อน +2

    Very well explained I always wondered how forwardRef work.
    Cheers 🍻 mate.

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน +1

      Glad it was a help!

  • @mounis
    @mounis 10 หลายเดือนก่อน +1

    Sorry for the out of context question, which font do you use?
    And BTW amazing explanation.

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน

      No worries. Cascadia code. Free font by Microsoft.

  • @grant_vine
    @grant_vine 10 หลายเดือนก่อน +2

    Nice overview and so simply shown

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน

      So glad it was a help!

  • @ronaldpaek
    @ronaldpaek 10 หลายเดือนก่อน +1

    I have a question about IDE's I remember watching some of your older videos and you used to use Nova IDE, just wanted to hear why you switched back to VS code I haven't seen many people use Nova IDE so I would love to hear about the Pros / Cons of Nova vs VS Code.

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน +1

      I haven’t used nova in a while, so I’m sure they’re much better now. I loved it but between viewers on the channel wanting to see VSCode and the lack of support for things like Astro originally, I switched.

    • @ronaldpaek
      @ronaldpaek 10 หลายเดือนก่อน

      that makes sense, I feel like most viewers/supporters will be using vs code 😆@@CodinginPublic

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

    nice understading

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

    Thank Chris! Really great explanation!

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

      Glad you found it helpful!

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

      @@CodinginPublic I did indeed. However, also in meanwhile I found to realise that forwardRef is to be deprecated soon and refs should be passed as props.

  • @ahtshamsaleem2970
    @ahtshamsaleem2970 4 หลายเดือนก่อน

    keep making more videos like these
    i loved it

  • @K.Huynh.
    @K.Huynh. 10 หลายเดือนก่อน

    thank for sharing! So cool 😎

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน

      Glad it was a help!

  • @yutsacarm8021
    @yutsacarm8021 3 หลายเดือนก่อน

    Omg !!!!! This is the. Best explanation of useRef video !!!

    • @CodinginPublic
      @CodinginPublic  3 หลายเดือนก่อน

      Glad it was helpful!

  • @chihuhahuana4863
    @chihuhahuana4863 4 หลายเดือนก่อน

    this video was actually so cool. thanks man!

  • @Aaronmoreno
    @Aaronmoreno 8 หลายเดือนก่อน

    So clear! I’m won over. I subbed

    • @CodinginPublic
      @CodinginPublic  8 หลายเดือนก่อน

      Great! Glad it was a help!

  • @adarsh-chakraborty
    @adarsh-chakraborty 10 หลายเดือนก่อน

    Thanks

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน

      Glad it was a help.

  • @KrunalShrimali-o4q
    @KrunalShrimali-o4q 10 หลายเดือนก่อน

    can we forward multiple refs at once to a component?

    • @CodinginPublic
      @CodinginPublic  10 หลายเดือนก่อน +2

      No, and something I should have mentioned (at least I don’t think you can). Typically you componetize individual inputs or items that need a ref (so single elements) when forwarding refs.

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

      Just pass refs as normal props. It works on older React versions too like 17.0.0. I don't understand why to even use fowardRef.