I want to make my async calls more readable
P粉573943755
P粉573943755 2024-04-05 15:34:44
0
1
3870

I currently handle my promises by calling an async function and chaining it with .then(). But I wish there was a more readable way.

My current feasible method is:

const apiCall = async() => {
  const response = await axios.get("URL");
  return response;
}

apiCall().then(res => {
  console.log(res.data);
});

I want my code to look like:

const apiCall = () => {
  const response = axios.get("URL);
  return response;
}

const fetchData = async() => {
  const response = await apiCall();
  return response.data;
}

console.log(fetchData());
P粉573943755
P粉573943755

reply all(1)
P粉726234648

how

const apiCall = async() => {
  const { data } = await axios.get("URL");
  return data;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template