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

99
Views
Get request inside afterupdate causes an infinitive loop Svelte

I am doing a get request on Svelte inside an after Update function. This creates an infinitive loop of get requests. How can I only get one request after a certain element is updated ?

For example in this case I am getting a list ,and I am using the afterUpdate because there is an option to delete lists and I want the user to see the updated list directly not after refreshing or navigating to other screens.

Or if there is another way except afterUpdate function to fulfill my purpose please let me know


 afterUpdate(async () => {
    const resp = await fetch(`__________/list`, {

    });

    if (resp.ok) {
      openlist = await resp.json();

    } else if (resp.data === "") {
      throw new Error("Could not find any company");
    }
  });```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could probably just use a reactive statement to trigger the fetch. E.g.

async function update() {
    // fetch here
}

// Whatever thing whose change should trigger the fetch
let someDependency;

$: someDependency, update();

(The update logic should not be inlined, otherwise the properties that are set within the function will also be tracked and you will potentially end up with a loop again.)

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!