An idiomatic way of using Svelte 5 and @tanstack/query! #7497
Unanswered
frederikhors
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Using Svelte with @tanstack/query is something magnificent and first of all I would like to warmly thank all the contributors, big and small.
Svelte 4
With Svelte 4 I always used this code:
even though I know that
$: playersStore
is recreated from scratch every time a dependency changes.It is simply so comfortable (and Svelte so fast and optimized) that the weight of recreating and some other problems do not bother and everything works well.
I know that docs page suggests to use
derived
store, but it's too complicated to use it when there are so many dependencies for a query.This is a simple example of my Svelte 4 code.
Svelte 5
Now for Svelte 5 I'm looking for a convenient way and it would be nice to combine all the ideas to have a common and idiomatic way and maybe - why not - even a nice article on the @TkDodo blog one day!
Since we can already use code with Svelte 5 syntax in our projects even if the components are still in Svelte 4 (great idea from the Svelte team!) I tried to use @tanstack/query in various ways, like many people.
So far the best solution is @nicksulkers's one:
utils.svelte.ts:
+page.svelte:
It works amazingly well! Here is a reproduction of it in my demo project.
But is this really an idiomatic way of using it?
For example, @Thiagolino8 proposed a similar way using:
What changes from the
reactiveQueryArgs
function? Why$effect.root
andreadable
store?It is also necessary to mention the excellent work of @zhihengGet who also proposed various forms of reactivity.
Will we be able to find a great way to this wonderful marriage?
Beta Was this translation helpful? Give feedback.
All reactions