I have a select that works fine but I need to capture the value that I am selecting, but it is generating an error Cannot read properties of undefined (reading 'value')
, i have not been able to solve it.
import React, { useState, useEffect } from "react";
import WindowedSelect from "react-windowed-select";
function App() {
const [t4t, setUniversidad] = useState([]);
const [e2, setE2] = useState(null);
console.log(e2 + " Seleccionado");
useEffect(() => {
(async () => {
const req = await fetch(
`https://witalenco.com.co/apiWittytalent/dyc/titulos/carreras.php`
);
const getres2 = await req.json();
console.log({ getres2 });
setUniversidad(await getres2);
})();
}, []);
// Here is the transformation
const options = t4t.map((item) => ({
label: item.carrera,
value: item.id_titulos
}));
const handlecountrye2 = (event) => {
setE2(event.target.value);
};
return (
<div>
<div class="col-12">
<br />
<WindowedSelect
options={options}
onChange={handlecountrye2}
value={e2}
name="e2"
/>
</div>
</div>
);
}
export default App;
https://codesandbox.io/s/dreamy-darkness-9z9cck?file=/src/App.js:0-992