react - ReactJS Refs - react js - reactjs
What is Refs in ReactJS?
- The ref is used to return a reference to your element.
- Refs should be avoided in most cases but they can be useful when you need DOM measurements or to add methods to your components.
learn reactjs tutorial -
reactjs events child
- reactjs example - react tutorial - reactjs - react
Using Refs
- Our example shows how to use refs to clear the input field.
- clearInputfunction is searching for element with ref = "myInput" value, resets the state and adds focus to it after the button is clicked.
App.jsx
Article tag : react , react native , react js tutorial , create react app , react tutorial , learn react
main.js
Output:
- Once the button is clicked, the input will be cleared and focused.