Answer the question
In order to leave comments, you need to log in
Why can axios, promises be returned, but not the result of a promise?
Why the first use case works and the second one doesn't.
Why can't you get the result of a promise right away?
Answer the question
In order to leave comments, you need to log in
Because asynchrony.
async getUser(userId) {
return await instance.get('...')
}
Why the first use case works and the second one doesn't.
You understand how promises work, right?
In both cases, when you call getUser() , a promise will be returned, but it will be resolved with different
parameters
. But the getUser method must return something as soon as it is called. It returns a pending promise until the promise is resolved/rejected . If the promise is resolved, the then method will be executed and you will be able to return some custom value from the promise. Has it
become a little clearer?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question