Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

React ref example

Refs in React is a shortcut way to access a specific DOM node or a React component.
There are two types of refs in react, string refs and callback refs.
In string refs we set the ref attribute to a name (string) and later access the element/component using the referenced name.

In this example let us see how to use a string ref to access the content in a textbox and display it in the screen. In this example we create a ref with name refName for the text control (ref="refName"). In the onChange() event of the control we get the content of the textbox using the ref and display it in the screen.



This post first appeared on C# Guide, please read the originial post: here

Share the post

React ref example

×

Subscribe to C# Guide

Get updates delivered right to your inbox!

Thank you for your subscription

×