Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda