2 回答
TA贡献1826条经验 获得超6个赞
每个async函数都返回Promise。就那么简单。
async setToken() {
const fcmToken = await firebase.messaging().getToken();
// Now if you console.log() the fcmToken will be string
return fcmToken;
}
console.log(setToken())
// This will be promise and inside will be fcmToken,
// because anything you return from async function will be wrapped in Promise.
TA贡献1824条经验 获得超6个赞
您还需要对await函数进行调用:
async onSubmit(e) { // <-- add "async" here
const {
navigation: { navigate },
credentials: { year, group, student },
fetchEvents
} = this.props;
// for that matter, this here being called "AsyncStorage" suggests
// that you *might* want to await this too.
AsyncStorage.setItem(
"loggedIn",
JSON.stringify(this.props.credentials)
);
const token = await this.setToken(); // <-- add "await" here
if (token) {
fetchEvents(student || group);
navigate("Month");
}
}
添加回答
举报