Is it possible to get the queryKey provided to useQuery from the return value of the same useQuery?
e.g.
const todoQueryResult = useQuery({queryKey: [a, b, c], queryFn: () => {fetch(url)}});
...
queryClient.setQueryData(todoQueryResult.queryKey, ....)
2 Replies
adverse-sapphireOP•3y ago
If it is not possible, is there any opposition to supporting this feature?
other-emerald•3y ago
Hi 👋
I’d suggest just variablising the query key. Query key factories are a popular approach. Alternatively, you can write a custom hook that exposes the query key in the return type