TanStackT
TanStack3y ago
6 replies
wet-aqua

typescript parallel useQuery/useInfiniteQuery type guard for data?

Hey there!

Is there a way/best practice to type guard multiple queries w/o using useQueries? I have a page that has a handful of mixed queries (regular and infinite) and what i would like to do is guarantee all have data before displaying anything. It's easily accomplished with a if
if (query1.data && query2.data && query3.data) { 
  /* JSX W/ DATA GUARANTEED */ 
}

but that gets unwieldy quick with more than a few queries. Extracting all that to a local var didn't do the trick since typescript only knows the var is "true" not that each data is defined. Any thoughts/recs from y'all? Thanks!
Was this page helpful?