Align useLiveQuery with useQuery, and remove dependency array #907
matthewdavi
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
|
Thanks for raising this discussion! I agree that dependency arrays aren't the best. One thing about this proposal that might confuse people coming from Query is that queryKey there is the key for the cache where with DB it's just to invalidate the hook. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
I will add my two cents here that I've forgotten to include the dependency array for queries multiple times and it always catches me off guard. |
Beta Was this translation helpful? Give feedback.
0 replies
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.
Uh oh!
There was an error while loading. Please reload this page.
-
🧩 Proposal: Deterministic Key / Dependency Handling in
useLiveQuerySummary
Currently,
useLiveQueryin TanStack DB relies on a referential-equality–based dependency array similar touseEffect, which can lead to brittle re-renders and makes reusable query abstractions difficult to write. By contrast, TanStack Query uses a deterministic hash of thequeryKey, resulting in predictable caching and better DX for reusable hooks.Problem
useLiveQueryaccepts(liveQueryFn, [deps])— similar to react query pre-v4, which makes it hard to create a singleliveQueryOptionsobject to pass into useLiveQueryuseQuery({ queryKey, queryFn }).Proposal
Align
useLiveQuerymore closely withuseQueryby introducing:and generating a deterministic hash of
queryDeps, similar to TanStack Query’s key hashing.Rationale
useQuery.Possible Implementation Paths
Short-term:
queryDepskey inside the options object.hashQueryKey).Long-term:
Notes
Beta Was this translation helpful? Give feedback.
All reactions