Reputation: 397
I have got a question. How do I get a result from function a async function?
This is my code:
function kakaoLogin() {
return async dispatch => {
RNKakaoLogins.login((err, result) => {
console.log(result);
});
console.log(result);
};
}
The first console.log(result) shows token!. but second console.log(result) does not show anything.
I want to get same result from second console.log(result) as first console.log(result)
Upvotes: 0
Views: 491
Reputation: 59004
function kakaoLogin() {
return async dispatch => {
RNKakaoLogins.login((err, result) => {
console.log(result);
});
console.log(result); // calling result outside its scope will not work
};
}
What do you expect with a null result? You are using result
outside of block.
If you want to do something in response. then you can make method call like.
function kakaoLogin() {
return async dispatch => {
RNKakaoLogins.login((err, result) => {
console.log(result);
doSomeWork(result);
// you can call another method here when you get response.
});
};
}
function doSomeWork(result){
.. somework
}
Upvotes: 2