T
TanStack3y ago
optimistic-gold

Complications of only being able to run useQuery in setup

Let’s say I do not yet have arguments that will yield an object of a certain shape from a query. So the result of the query will be some nullish value or empty object I do not necessarily want to run the query until I know the response will yield an object of the correct shape for reactivity / performance reasons. (Bad to add keys to object, won’t be reactive without workaround) A strategy I have that’s currently working is to just nest the returned object in a “data” key so that I can still track reactivity. I can make this a bit cleaner by returning a computed function thay returns this key instead of the normal data object from the useQuery composable. This solves the reactivity issue. I’m thinking about some other strategies like disabling the query initially, using the query client in a watcher, and some more. Before I get too deep in the rabbit hole just wanted to check in with some people smarter than me 😂
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?