What is the best practice of using Svelte Query with SvelteKit?
First, I tried to use useQuery inside an endpoint, but I got the error message
Function called outside component initialization.
Then I used the data from the endpoint as initalData. But then the endpoint is called every time I load the page even if there is a cache.
export let accounts
const result = useQuery('accounts', getAccounts, {
initialData: accounts,
})
Now I'm trying queryClient.setQueryData('accounts', accounts) inside the endpoint. But the endpoint doesn't have access to the same queryClient as the front-end so I guess that won't work. I also get a
Cannot read property 'fallthrough' of undefined error.
What is the best practice of using Svelte Query with SvelteKit?
First, I tried to use
useQuery
inside an endpoint, but I got the error messageFunction called outside component initialization
.Then I used the data from the endpoint as
initalData
. But then the endpoint is called every time I load the page even if there is a cache.Now I'm trying
queryClient.setQueryData('accounts', accounts)
inside the endpoint. But the endpoint doesn't have access to the same queryClient as the front-end so I guess that won't work. I also get aCannot read property 'fallthrough' of undefined
error.Any tips?
Thanks!