i'm really new with js amd currentrly tring to make an app that gets data from a db in mysql using axios for the requests, to then pass the data to an array with an useState hook, on an array however i'm always facing the issue that the .then promise not always waits for the response to come, before executing other funcions inside it. Here:
const filtrarNombres =()=> {
Axios.get('http://localhost:3001/api/getFiltrado', {params:{diasRestantes : document.getElementById("filtroDias")
.value, money : document.getElementById("filtroMoneda").value }}).then(response => {
setServLista(response.data);
return(console.log(response.data));
})
}
so, thanks to the console.log(response.data) i can see that it's the correct array of data, however, the setSerLista(response.data) is not waiting for the reponse to come, and triggers with nothing, causing a bunch of error when trying to render that.
this functions triggers onChange of a select list, basically what it does, it's that it sends the two params as filters for a select on mysql, the response, on the console.log is the expected one.
Thanks for taking your time reading!
i tried making the function async and adding await before the response, i also tried setting a timeout on setServLista(response.data); with no luck, it stills tries to render invalid data.