When does load and preload run?

I started a solidstart project I'm toying with and I'm not understanding some of the data fetching model.
export const route = {
load: async () => {
console.log("load!");
},
preload: async () => {
console.log("preload!");
},
} satisfies RouteDefinition;
export const route = {
load: async () => {
console.log("load!");
},
preload: async () => {
console.log("preload!");
},
} satisfies RouteDefinition;
Is there any point combining the two? Because I only see "load" when I comment out the preload function. But either way, when I hover the link it still preloads but calls the load function. When and for what should I use them?
3 Replies
Brendonovich
Brendonovich3w ago
load is the old name for preload, it's a feature of solid router: https://docs.solidjs.com/solid-router/reference/preload-functions/preload they're called before navigating and on link hovers so that you can start fetching data earlier
notherpleb
notherplebOP3w ago
Ok, that makes more sense. Just to be sure, you retrieve that preloaded data by defining some getData wrapped by a query?
Madaxen86
Madaxen863w ago
Yes.
Want results from more Discord servers?
Add your server