使用axios和React创建轮询

时间:2019-07-30 13:41:23

标签: reactjs axios polling

我正在尝试使用React实现axios极化。我期望get请求返回某个值,但是因为它是异步方法,所以我必须等待它。

反应方法:

 getInformationMessageOnSubmit = () => {
     getInformationMessage().then(output => 
     this.setState({message: output})
  };

我在另一个文件中也有一个axios请求:

const getInfo = () => {
  return axios.get('url')
    .then(output => output)
    .catch(error => console.log(error))
}


export const getInformationMessage = sealId => {
  setInterval(() => getInfo(sealId), 1000);
};

0 个答案:

没有答案