Почему результат промиса в данном случае можно получить с помощью async/await?
Почему результат промиса в данном случае можно получить с помощью async/await? Хотелось бы понять почему так происходит
c async/await - возвращает массив с данными:
useEffect(async () => {
function getData(){
return axios.get('http://www.filltext.com/?rows=32&id={number|1000}&firstName={firstName}' +
'&lastName={lastName}&email={email}&phone={phone|(xxx)xxx-xx-xx}&address={addressObject}&description={lorem|32}\n' +
'\n').then(response => {
return response.data
})
}
const result = await getData()
console.log(result)
}, [])
без async/await - возвращает Promise:
useEffect(() => {
function responseData(){
debugger
return axios.get('http://www.filltext.com/?rows=1000&id={number|1000}&firstName={firstName}&delay=3&lastName={lastName}&email={email}&phone={phone|(xxx)xxx-xx-xx}&address={addressObject}&description={lorem|32}\n' +
'\n').then(response => {
return response.data
})
}
const promise = responseData()
console.log(promise)
}, [])