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

232
Vistas
UseEffect creates a loop + does not pass parameters to UrlParams

Trying to create a switch to filter through on-site/remote job posts using UseEffect but it creates an infinite loop and I can't figure out why. (jobCondition, in this case, is UseState hook) + when I try to pass params in conditions: ${condition}, it does not work. Can somebody help explain to me what am I doing wrong in these 2 cases? Thanks!

const getJobsLocation = async () => {
    const queryParams = { page: 1, limit: 10 };
    const response = await getJobs(queryParams);
    if (!response) {
      return;
    }
    const searchResults = [];
    response.data.nodes.forEach((loc) => {
      searchResults.push({ title: loc.jobLocation });
    });
    getJobsLocation(searchResults);
    console.log(searchResults);
  };
  useEffect(() => {
    let condition = getJobsLocation();
    switch (jobCondition) {
      case 'On-site': condition.filter((con) => con.jobLocation === 'in_person');
        break;
      case 'Remote': condition.filter((con) => con.jobLocation === 'remote');
        break;
      case 'Hybrid': condition.filter((con) => con.jobLocation === 'hybrid');
        break;
      default:
        condition = null;
    }[condition];
    if (condition != null) {
      const params = new URLSearchParams({
        jobs: jobFilter || null,
        location: locationFilter || null,
        since: datePosted || null,
        conditions: `${condition}`,
      });
      history.push({ pathname: '/', search: `${params.toString()}` });
      return;
    }
    const params = new URLSearchParams({
      jobs: jobFilter || null,
      location: locationFilter || null,
      since: null,
      conditions: null,
    });
    history.push({ pathname: '/', search: `${params.toString()}` });
  }, [jobCondition]);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

please note that let condition = getJobsLocation(); this function is an async function that needs to be await'ed on.. and it actually returns nothing so even after you await it it will be the condition variable will be undefined

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