Swacblooms🦋

Making the Moves
Menu
  • Home
  • Motivation
  • Education
  • Programming
  • About
  • Contact
  • Privacy Policy
Home
Programming
React Refs the easy way
Programming

React Refs the easy way

Samson Amaugo September 2, 2019

Hey guys I’m back and banging and in today’s post we gonna be talking about React Refs..

Refs can be seen as a way of making reference to a DOM node or component. In react the gateway of interaction between a parent and child component is usually with the use of props. But sometimes we may need to interact with a component or an element that is outside the normal data flow and that is when Refs come in view.

There are some important uses of ref but in this article but we would demonstrate using ref’s to activate the focus of an input element.

Okay to clarify this I would illustrate this using vanilla JavaScript.

See the Pen Focus in Vanilla JavaScript by Samson Amaugo (@Sammy360) on CodePen.

In the example above you can see that when the Button is clicked the input field gains focus.

Now let us try this out with React Ref

See the Pen Using Refs by Samson Amaugo (@Sammy360) on CodePen.

From the example above you can see how we accomplished the same function in both React and Vanilla JavaScript.

One thing to note from the React implementation is that to use the ref we had to assign a variable to the React.createRef() API. This method would form the connection in the node where the ref prop is assigned.

Also note that ref are not usually used in functional component because they don’t have instances.

You also don’t need to make use of the React.createRef() API always as we can make use of the callback implementation. In the next lesson we would discuss how to use the callback method.

If you have any question …please don’t fail to put it down in the comment section below

Prev Article
Next Article

Related Articles

DNA pairing
The DNA strand is missing the pairing element. Take each …

DNA Pairing

Hello y’all, in this post I would be writing on …

Case Statement: Ruby

About The Author

Samson Amaugo

I am Samson Amaugo. I am a full-stack developer and I specialize in DotNet and the MERN stack.

Search Site

Recent Posts

  • Cloudflare Tunnel to Postgres, plus Swarm’s static IP problem
  • The Topological Sort
  • Building a Perceptron in .NET
  • Part 4 — Assertions: Verifying What You See
  • Part 3 — Actions and Auto-Waiting: Putting Locators to Work

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 feed: Swacblooms Swacblooms

Swacblooms🦋

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