I'm trying to make a fetch function that return the data like a classic function. like this :
function fetchGetData(idUser){
fetch('url?idU='+idUser)
.then((response)=>console.log(response))
.then((responseText)=>{
if(responseText.result!='true'){
console.log(responseText)
return parseInt(responseText) // return the data (a number for me)
}
else {
return 0 ;
}
});
}
then I want to use the function like this : var data = fetchGetData(id); I'm new on react, I don't know if its possible. In my context, i can't use states to save it in the function. Any ideas? Thank you