I have the following code:
const [intrebari, setIntrebari] = useState([])
useEffect(() => {
let idVar = localStorage.getItem('idVarianta');
idVar = JSON.parse(idVar)
axios({
method: "POST",
data: {
idVarianta: idVar,
},
withCredentials: true,
url: "http://localhost:4000/getIntrebari",
}).then((res) => {
console.log(res)
const data = res.data;
setIntrebari(data);
console.log('Data has been recieved');
});
}, [])
How can I access the data? If I try intrebari[0].intrebare it gives me "Cannot access property intrebare of type undefined". Any idea? I tried also to console log intrebari[0] and it's displaying the first element, but when i'm trying to access intrebari[0].intrebare it gives me the error described above. Thanks
