SvelteStack / svelte-query

Performant and powerful remote data synchronization for Svelte
https://sveltequery.vercel.app
MIT License
822 stars 30 forks source link

Clarify: “ violate the rules of hooks” #57

Open derolf opened 3 years ago

derolf commented 3 years ago

https://sveltequery.vercel.app/guides/parallel-queries

Dynamic Parallel Queries with useQueries

If the number of queries you need to execute is changing from render to render, you cannot use manual querying since that would violate the rules of hooks. Instead, Svelte Query provides a useQueries hook, which you can use to dynamically execute as many queries in parallel as you'd like.

I am verify familiar with the concept of hooks and all their pitfalls in React, but this is the first time I read something mentioning rules of hooks in Svelte.

Can you please elaborate what can go one calls useQuery conditionally?

paolotiu commented 3 years ago

I think the docs were basically copied and pasted from react-query.

derolf commented 3 years ago

Yeah, that’s what I figured out as well. Anyway, I think the docs should be fixed…

SomaticIT commented 2 years ago

Since useQuery creates a Readable store. It can't be conditionnally executed (svelte compiler will try to subscribe to it anyway).