0

I'm trying to wrap fetch() and return the JSON data from it:

function testFetch() {
    fetch('/xxx/').then(
        (resp) => {
            resp.json().then((data) => {
                console.log('inside', data)
                return data
            })
        }).catch((err) => {
            console.log('error', err)
        })
}

console.log(testFetch())

It obviously does not work, how can I wait for fetch() to complete?

Progman
  • 16,827
  • 6
  • 33
  • 48
daisy
  • 22,498
  • 29
  • 129
  • 265

0 Answers0