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

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.