Skip to main content

react from handerler

  form handler

1 step 

const [user ,setUser]= useState({
  email:"",
  password:''
})
// 2 step
 <input onChange={handleChange} value={user.email} id="email-address"
name="email" type="email" autocomplete="email" required >

//3 step
          <form onSubmit={dataHandler} class="mt-8 space-y-6"
action="#" method="POST">

4 step
function handleChange(evt) {
  const value = evt.target.value;
  setUser({
    ...user,
    [evt.target.name]: value
  });

5 step
const dataHandler = (e)=>{
  e.preventDefault()
console.log(user)
}




Comments

Popular posts from this blog

ajeet

 

JavaScript Hash function

 java Script hash  code for genrating sam number as  function hashCode ( string ) { let hash = 0 ; if (string. length == 0 ) { return hash; } for ( let i = 0 ; i < string. length ; i++) { let char = string. charCodeAt (i); hash = ((hash<< 5 )-hash)+char; hash = hash & hash; } return hash; } let input = document . querySelector ( "#input" ) let output = document . querySelector ( "#output" ) input. addEventListener ( "keyup" , () => { output. value = hashCode (input. value ) }) html < p > Enter text here </ p > < input type = "text" id = "input" > < p > 'Random' number outputted here </ p > < input type = "text" disabled = "disabled" value = "" id = "output" >