Kamil
Kamil2w ago

What is the substitution for queryKey in useQuery?

In vanilla @tanstack/react-query, queryKey works as dependencies referrence so the query refetches automatically as it changes. Just like useEffect's dependency array. It's not present in tRPC flavoured useQuery, looks like it is handled automatically. So what to do instead? How to attach such dependencies to query?
1 Reply
FluX
FluX2w ago
If you have a useQuery hook like const hook = trpc.getUsers.useQuery({ username }), where username is a state that's tied to a search input, the query will re-run automatically when username changes. No dependency array needed

Did you find this page helpful?