如何在函数中将此添加到handleChange和componentDidMount的回调中?
// callback from github api /api.github.com/repos/{user}/{repo}
const [repository, issues] = await Promise.all([
api.get(`/repos/${repoName}`),
api.get(`/repos/${repoName}/issues`, {
params: {
state: 'all',
// I need change this by select options = all, closed and open (per example)
per_page: 5,
},
}),
]);
// this define setState again in handleChange
this.setState({repository: repository.data,
issues: issues.data,
loading: false,
});
// Example:
componentDidMount () {functionUP();};
handleChange () {functionUpAgain(with state from params = all, open or closed);
};
由于您正在使用await
,因此您的功能必须为async
。