If you don't return the promise from your function that fetch()
creates, then your function is just returning undefined
and NOTHING is communicated back to the caller. You have to return the promise.
The return of your data is a return to the .then()
callback. That's not a return from your function. That return is also needed because that sets the resolved value of the parent promise, but that just returns back from the callback into the promise infrastructure and is not a return from your function itself. To return from the function itself, you need a return
that isn't nested inside some other function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…