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

220
Vistas
React call function inside itself

I want to call an arrow function inside itself in React.

I am fetching an api but if api response with status code 401, I do some things (that work as expect) and then I need to reexecute the function tokenGet. How can I do this? I tried this way below and with return tokenGet(url); and all ways result on a infinite loop on api.

const tokenGet = (url) => {
    const data = {
      ...
    };
    return fetch(url, data)
      .then(res => {
        if (res.status === 401) {
          ...
          tokenGet(url);
        } else {
          return res.json();
        }
      });
  };

I am calling above function this way on another component.

useEffect(() => {
    tokenGet(url)
      .then(data => {
        ...
      });
  }, []);
about 4 years ago · Juan Pablo Isaza
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