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
Post a Comment