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

226
Views
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 answers
Answer question

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 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!