I'm working on a page with 2 dependent queries. One depends on a page parameter and one depends on another query. If I roughly follow the tutorial, I get this:
This isn't necessarily shorter than the other ones, but it's definitely cleaner and it can be put inside a function somewhere and imported in a component.
And now we can use Svelte Query in 2 lines from a component's perspective. Doing this with the current API requires quite a lot of boilerplate that could be saved by generator functions.
I'm working on a page with 2 dependent queries. One depends on a page parameter and one depends on another query. If I roughly follow the tutorial, I get this:
There's an apparent problem: I have to re-type the entire thing every time something changes.
One could just re-create the entire query reactively, but it doesn't feel right. There must be a reason for the
enabled
parameter to exist.Working with this doesn't feel good and I'm trying to find solutions to tap in SvelteQuery's great features but with an API that's a bit less insane.
What if it was generated on the fly?
When a query is created, we know what we want to send it even if we don't have it yet. Example:
profile
.profile
profile
Why not use generator functions to generate the ID and the fetch only when
enabled
is turned on?This isn't necessarily shorter than the other ones, but it's definitely cleaner and it can be put inside a function somewhere and imported in a component.
And now we can use Svelte Query in 2 lines from a component's perspective. Doing this with the current API requires quite a lot of boilerplate that could be saved by generator functions.
One could make generator functions to avoid duplicating code in
api.ts
but it's even more boilerplate for something that should be simple.