Hi I am dynamically trying to set input values in react-hooks concept, but I am encountering an error. Could someone help me with this:
Code:
import React,{useState} from 'react';
function ObjectHook() {
var [names,setName]=useState({fname:'',lname:''});
let UpdateData = (event) =>{
setName({...names,[event.target.name]:event.target.value})
}
return(
<div>
<input type='text' name='fname' value={names.fname} onChange={UpdateData}>First Name</input>
<input type='text' name='lname' value={names.lname} onChange={UpdateData}>Last Name</input>
<h1>{names.fname}</h1>
<h1>{names.lname}</h1>
</div>
)
}
export default ObjectHook;
