-5

Is Axios async by it self, or is it needed to wrap it around an async function? For instance is this async :

function axios () {
  axios.get()
}

Or should I write it like this:

async function axios () {
  await axios.get()
}

Thanks in advance

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Amin Darian
  • 177
  • 2
  • 11
  • 1
    `axios.get` returns a promise, whether you wrap it into a function, an async function, or not at all. How you *deal* with that returned promise is what you have to decide, whether to `await` it or anything else. – deceze Aug 26 '20 at 08:42
  • 2
    your overwriting axios with a function called axios – Lawrence Cherone Aug 26 '20 at 08:43

1 Answers1

2

Axios returns promise so you can use async await or .then

async await :

async function call() {
  const { data } = await axios.get('api/test')
}

then :

 function call() {
  axios.get('api/test').then(({data}) => {..operation here..})
}
Radical Edward
  • 2,824
  • 1
  • 10
  • 23