每20秒钟致电API,然后停止特定响应
从渲染组件的那一刻起,我想每20秒钟致电一次API,并且在提供特定响应时必须停止API调用。
解释更多。有一个API获取方法,它将像下面一样发送响应。 {firstWork:'Success',二项工作:'成功',第三项工作:'过程中'} ,
所以我想从组件渲染的点开始定期/反复(每20秒)调用此API(每20秒)直到所有这些变成“成功”。 {firstWork:'Success',秒为:'成功',第三项:'Success'}
当我得到上述响应时,我应该停止调用API GET方法。如何在ReactJ中实现它?
I want to call my API every 20 seconds from the moment where the component is rendered and the api calling has to stop when it provides a specific response.
Explaining more. There is an API get method which will send a response like below.
{firstWork : 'Success' , SecondWork : 'Success' , ThirdWork : 'IN-Progress'}
So I want to call this API periodically/repeatedly(every 20sec) from the point where the Component is Rendered and till all these becomes 'Success'.
{firstWork : 'Success' , SecondWork : 'Success' , ThirdWork : 'Success'}
When I get the above response I should Stop calling the API get method. How can I achieve it in ReactJS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在组件中设置
setInterval
来实现这一目标。You can achieve that by setting a
setInterval
inside your component.