Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Calling API every 20 Seconds and Stop on a Specific Response

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can achieve that by setting a setInterval inside your component.

import { useEffect } from "react"

const Component = () => {
  useEffect(() => {
    const interval = setInterval(() => {
      fetch("/yourApiEndpoint")
        .then(res => res.json())
        .then(json => {
          if(json.thirdWork === "Success"){
            clearInterval(interval)
          }
        })
    }, 20*1000)
  },[])

  return <p>component</p>
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!