Swacblooms🦋

Making the Moves
Menu
  • Home
  • Motivation
  • Education
  • Programming
  • About
  • Contact
  • Privacy Policy
Home
Programming
React- Forwarding Refs
Programming

React- Forwarding Refs

Sammy September 5, 2019

Yo guys I’m back and banging today with using React’s forwarding Technique.

Since React paradigm is based on components and its encapsulations with other components, sometimes you might want to gain access to the node of a child element in a parent element.

In the example above you can see that a ref was created. But the problem with the code above is that you can’t reach the button element in the SmileyButton’s component. So to make this work we are going to make use of the forwardRef procedure.

You need ref forwarding to allow a component to pass refs to their parent-child. An example can be seen below.

If you run the code above you would notice that you have access to the ref of the button. And therefore you can control it from its ancestral parents.

React.forward Refs receives two arguments: props and ref

Please note that the ref’s argument of React forward won’t work on regular functions and class components.

You can read up more on refs to increase your knowledge span.

Thanks guys… You can comment below to contribute

Prev Article
Next Article

Related Articles

reference
Hey guys I’m back and banging and in today’s post …

React Refs the easy way

regex
Hello guys, so in this post, I would be writing …

Manipulating the Prisma Schema Using Regex.

About The Author

Sammy

I am Samson Amaugo. I am a full-stack web developer and I specialize in MERN stack development

2 Comments

  1. Osinachi Victor Chukwujama

    Is this stuff working

    January 17, 2020
    • Sammy

      Yep it works quite well bro

      January 20, 2020

Leave a Reply

Cancel reply

Search Site

Recent Posts

  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet
  • Dynamic Subscriptions in Hot Chocolate 🔥🍫
  • Deploying a DotNet API To Railway 🚂
  • GitHub OAuth Device Flow in DotNet

Categories

  • EDUCATION
  • Motivation
  • Programming
  • Uncategorized

Get more stuff

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

we respect your privacy and take protecting it seriously

RSS Swacblooms

  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet
  • Dynamic Subscriptions in Hot Chocolate 🔥🍫
  • Deploying a DotNet API To Railway 🚂
  • GitHub OAuth Device Flow in DotNet
  • Resumable Download in DotNet
  • Mocking the HttpClient in C#
  • MySocials DotNet CLI Tool
  • Benchmarking in C#
  • C# bang bang operator

Swacblooms🦋

Making the Moves
Copyright © 2023 Swacblooms🦋
Swacblooms - Making the Moves