In sveltekit, a +page.svelte renders the data that was loaded using a +page.ts load function.
But what if there is a Button on the page like "more data..." to load additional data.
How to tell the load function to run again, but with different parameters?This may work with url parameters, I guess, but what if you do not want to use these url parameters?
What I did until now, was having the data loading completely inside the +page.svelte, what was quite easy because I just hold the state of:
const top = 10let skip = $state(0)let data = $state([])async function loadData(top, skip) { //... data = [data..., newdata]}
And when a button is clicked, it increases the skip and this triggers the loadData.
But this does not seem to be the Sveltekit way, I guess.I have no idea, how to do this with such a load function.
I could also load the additional data inside the +page.svelte, but this would then maybe conflict with the load function. I would have to merge the data from the load function with the data loaded in the actual +page.svelte and if the load function gets invalidated it may be inconsistent.
Is there any best practice for that?
There should be a lot of scenarios like this, where the initial data loading is not enough and a page has to load some more data at a later point in time.