useRef Hook example in React Js

 App.js:

import React, {useRef} from "react";
import './App.css'

function App()
{
  let inputRef=useRef(null)

  function handleInput()
  {
    console.warn("handleInput Called")
    inputRef.current.value="2000"
    inputRef.current.focus();
    inputRef.current.style.color="red"
  }
return(
  <div>
    <h1>Use Ref Tutorial</h1>
    <input type="text" ref={inputRef}/>
    <button onClick={handleInput}>Handle Input</button>
  </div>
)
}
export default App;




Comments

Popular posts from this blog

Send Data Child to Parent Component - React Js

Hide , Show and Toggle in ReactJs

Importance Of Web Content In SEO.