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

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