如何在函数中将此添加到handleChange和componentDidMount的回调中?

问题描述 投票:0回答:1

如何在函数中将此添加到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);
};
javascript reactjs callback
1个回答
0
投票

由于您正在使用await,因此您的功能必须为async

© www.soinside.com 2019 - 2024. All rights reserved.