Svelte · Senior · Question 24 of 75

How do you trigger a reload of specific data after a mutation?

// +page.js
export async function load({ fetch, depends }) {
  depends("app:cart");
  return { cart: await (await fetch("/api/cart")).json() };
}

// somewhere in the UI
await invalidate("app:cart");

Explanation

Form actions with use:enhance invalidate all data automatically after a successful submission.

Further reading

Problem with a question

Svelte · Senior · question 24

Test yourself

Take the Svelte · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz