Home > Back-end >  How event.target.name.value works
How event.target.name.value works

Time:05-09

So i've been trying to use event.target.name.value for an input field but when i submit the form, the values are null and i have to click twice to get the values. Here is my code:

const [name, setName] = useState('');
const handleSubmit = (event)=> {
  setName = event.target.name.value;
  console.log(name);
}

What am i doing wrong?

CodePudding user response:

You are setting the function which is wrong. you need to pass it as parameter to setName function.

const [name, setName] = useState('');
console.log(name);
const handleSubmit = (event)=> {
  setName(event.target.value);
  
}

CodePudding user response:

brother event.target.name.value it will take the value from your targeted input like name is a

  • Related