My goal is to collect all the values from the selected option into a state. How to do it correctly? I thought about how to refer to the attributes of the selected option, but I did not succeed. I have the following State
const [search, setSearch] = useState({
phone: "",
mark: "",
model: "",
name: "",
})
Here is my onChange function
const onSearchChange = (e) => {
const { name, value } = e.target
setState((prevState) => ({
...prevState,
[name]: value,
}))
}
And there is a Select mapping values from an object. So such values as {it.name}, {it.mark}, {it.model} and so on I want to collect in the search state
<select
className="block appearance-none w-full"
value={search}
name="search"
id="searchBlock"
onChange={onSearchChange}>
{customerList.map((it) => {
return (
<option
value={it.name}
phone={it.phone}>
{it.name}, {it.mark} {it.model} {it.regnumber}, {it.phone}
</option>
)
})}
</select>