Get Input Box Value - React Js
App.js:
import React, {useState} from 'react';
import './App.css'
function App()
{
const [data, setData]=useState(null)
const [print, setPrint]=useState(false)
function getInputValue(val)
{
console.log(val.target.value)
setData(val.target.value)
setPrint(false)
}
return(
<div className="App">
{
print? <h1>{data}</h1> : null
}
{/* <h1>{data}</h1> */}
<input type="text" placeholder="Enter Value" onChange={getInputValue}/>
<button onClick={()=>setPrint(true)}>Print Value</button>
</div>
)
}
export default App;
Comments
Post a Comment