const onInputChange = e => {
const { target: { name, value } } = e;
console.log(value);
const updatedInputs = { ...inputs, [name]: value };
setInputs(updatedInputs);
onScreenData.current = updatedInputs;
};
<div>
<h2>Use refs to get the latest inputs value</h2>
<label>Title: </label>
<input name="title" value={inputs.title || ""} onChange={onInputChange} />
<label>Note: </label>
<input name="note" value={inputs.note || ""} onChange={onInputChange} />
</div>
var e = {
target: {
name: "Lionel",
value: 12
}
}
var { target: { name, value } } = e;
console.log(value);
var updatedInputs = { ...e, [name]: value };
console.log(updatedInputs);
{
"target": {
"name": "Lionel",
"value": 12
},
"Lionel": 12
}