Never Forget React forwardRef Again

Sdílet
Vložit
  • čas přidán 29. 07. 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/coding-in-public/r...
    - Forward Ref docs: react.dev/reference/react/for...
    ---------------------------------------
    🌐 Connect With Me 🌐
    - Website: codinginpublic.dev
    - Blog: chrispennington.blog
    - Twitter: / cpenned
    - Patreon: / coding_in_public
    - Buy Me a Coffee: www.buymeacoffee.com/chrispen...
  • Jak na to + styl

Komentáře • 68

  • @alinikpey5797
    @alinikpey5797 Před 8 měsíci +10

    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  Před 8 měsíci +1

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

  • @raldskie23
    @raldskie23 Před 8 měsíci +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  Před 8 měsíci

      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!

  • @SouravDuttaROCKSTAR
    @SouravDuttaROCKSTAR Před 8 měsíci +4

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

    • @CodinginPublic
      @CodinginPublic  Před 8 měsíci +3

      Glad it was a help! Thanks for saying something!

  • @akash-kumar737
    @akash-kumar737 Před 8 měsíci +2

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

  • @morchellemusic2829
    @morchellemusic2829 Před 7 měsíci +1

    Thanks for the explanation, very clear and concise

  • @yutsacarm8021
    @yutsacarm8021 Před měsícem

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

  • @grant_vine
    @grant_vine Před 8 měsíci +2

    Nice overview and so simply shown

  • @osifojohn1513
    @osifojohn1513 Před měsícem

    Love this video, you cleared all my doubts.

  • @DashFactsCentral
    @DashFactsCentral Před 5 měsíci

    Very beautifully explained! Thanks alot!

  • @__greg__
    @__greg__ Před 6 měsíci

    This was a great explanation, thanks for sharing!

  • @chihuhahuana4863
    @chihuhahuana4863 Před 2 měsíci

    this video was actually so cool. thanks man!

  • @godofwar8262
    @godofwar8262 Před 8 měsíci +2

    Thank you finally a react video

  • @RandomMcLain
    @RandomMcLain Před 8 měsíci +2

    🎯 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

  • @ahtshamsaleem2970
    @ahtshamsaleem2970 Před 2 měsíci

    keep making more videos like these
    i loved it

  • @prashlovessamosa
    @prashlovessamosa Před 8 měsíci +4

    Thanks for sharing please make more react stuff.

  • @sahilrathod3930
    @sahilrathod3930 Před 7 měsíci +1

    Great explanation... ❤

    • @CodinginPublic
      @CodinginPublic  Před 7 měsíci

      Thanks for saying something! Glad it was a help!

  • @K.Huynh.
    @K.Huynh. Před 8 měsíci

    thank for sharing! So cool 😎

  • @Firewallx2
    @Firewallx2 Před 3 měsíci

    Thanks!

  • @Aaronmoreno
    @Aaronmoreno Před 6 měsíci

    So clear! I’m won over. I subbed

  • @adarsh-chakraborty
    @adarsh-chakraborty Před 8 měsíci

    Thanks

  • @sandiladhikari7903
    @sandiladhikari7903 Před 11 dny

    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 ?

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt Před 7 měsíci

    Awesome

  • @mounis
    @mounis Před 8 měsíci +1

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

    • @CodinginPublic
      @CodinginPublic  Před 8 měsíci

      No worries. Cascadia code. Free font by Microsoft.

  • @ahmadm.hawwash3931
    @ahmadm.hawwash3931 Před 26 dny

    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?

  • @ronaldpaek
    @ronaldpaek Před 8 měsíci +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  Před 8 měsíci +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 Před 8 měsíci

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

  • @user-lt1jr2gh4t
    @user-lt1jr2gh4t Před 8 měsíci

    can we forward multiple refs at once to a component?

    • @CodinginPublic
      @CodinginPublic  Před 8 měsíci +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 Před 14 dny

      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.

  • @mohammadalrefaai4377
    @mohammadalrefaai4377 Před 6 měsíci

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

  • @ayushnautiyal9469
    @ayushnautiyal9469 Před 5 měsíci

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

    • @CodinginPublic
      @CodinginPublic  Před 5 měsíci

      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 Před 14 dny

      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.

  • @nicus1504
    @nicus1504 Před 27 dny

    You CAN pass refs directly as props

    • @CodinginPublic
      @CodinginPublic  Před 27 dny

      You can now in react 19. :)

    • @Kraszer
      @Kraszer Před 14 dny

      @@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 Před 4 měsíci

    {2024-03-22}

  • @anhdunghisinh
    @anhdunghisinh Před 3 měsíci

    And now they ditch forwardRef :v

  • @ChristinaCodes
    @ChristinaCodes Před 8 měsíci

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

    • @CodinginPublic
      @CodinginPublic  Před 8 měsíci +1

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

  • @carlandres3319
    @carlandres3319 Před 5 měsíci

    Thanks