Svelte · Senior · Question 25 of 75

Why should load functions be free of side effects?

// +page.js
import { user } from "./state.svelte.js";
export async function load({ fetch }) {
  user.current = await (await fetch("/api/user")).json();
}

Explanation

Return the data and let components read it via data or pass it into context.

Further reading

Problem with a question

Svelte · Senior · question 25

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