// Get all input value by onKeyUp event using one function
const [student, setStudent] = useState({});
const setStudentValue = (e) => {
let set = {};
set[e.target.name] = _.trim(e.target.value);
setStudent({
...student,
...set
});
}
// <input type="text" name="firstName" onKeyUp={setStudentValue} />
// set data
// {firstName: ""} - output
import { useState } from 'react';
const CityNameInput = () => {
const [cityName, setCityName] = useState('Seattle');
const renameCity = (changeEvent) => {
console.log('Details about the element that fired the event:', changeEvent.target);
console.log('The value of that element:', changeEvent.target.value);
setCityName(changeEvent.target.value);
};
return (
<section>
<h2>{cityName}</h2>
<input type="text" value={cityName} onChange={renameCity} />
</section>
);
};