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");- ✓Correct answer: Declare a custom dependency with
dependsand callinvalidatewith the same identifier - 2Reload the whole page
- 3Call
load()directly
Explanation
Form actions with use:enhance invalidate all data automatically after a successful submission.