Je gère actuellement mes promesses en appelant une fonction asynchrone et en la chaînant avec .then(). Mais j'aimerais qu'il y ait une manière plus lisible.
Ma méthode réalisable actuelle est :
const apiCall = async() => {
const response = await axios.get("URL");
return response;
}
apiCall().then(res => {
console.log(res.data);
});
Je veux que mon code ressemble à :
const apiCall = () => {
const response = axios.get("URL);
return response;
}
const fetchData = async() => {
const response = await apiCall();
return response.data;
}
console.log(fetchData());
Comment
const apiCall = async() => { const { data } = await axios.get("URL"); return data; }