我正在用react native和expo构建一个应用程序。如何在箭头函数中调用相邻函数。不会从funcOne
调用funcTwo
,也不会出现警告/错误。
// Call first fucntion inside MainScreen.js
import Fire from '../Fire';
export default class MainScreen extends React.Component {
makeRemoteRequest = async () => {
const res = await Fire.shared.funcOne({ title: "test" });
}
};
// Fire.js
class Fire {
funcOne = async ({title}) => {
this.funcTwo(title);
};
funcTwo = async (title) => {
// save to database
console.log(title);
};
}
Fire.shared = new Fire();
export default Fire;
发布于 2019-09-28 09:40:53
funcOne
中缺少await
调用funcTwo
时,如果要返回funcTwo
的值,则可以省略await
,但不是这样
所以..。
// Call first fucntion inside MainScreen.js
import Fire from '../Fire';
export default class MainScreen extends React.Component {
makeRemoteRequest = async () => {
const res = await Fire.shared.funcOne({ title: "test" });
}
};
// Fire.js
class Fire {
funcOne = async ({title}) => {
// Here you should add await
await this.funcTwo(title);
// or
// return this.funcTwo(title);
};
funcTwo = async (title) => {
// save to database
console.log(title);
};
}
Fire.shared = new Fire();
export default Fire;
https://stackoverflow.com/questions/58143315
复制相似问题