TanStackT
TanStack2y ago
2 replies
rubber-blue

How to check if useQuery data changed

Hi I'm new to this so sorry if this is easy to do but i cannot figure out how to check if the data in the useQuery has updated. The reason I need to check this is cause i have another value I want to change only when data changes and not on every render.

This is my query

export const useDocuments = () => {
  return useQuery({
    queryKey: ["documents"],
    placeholderData: [],
    queryFn: async () =>
      await invoke("get_documents")
     .then((res) => {
        return res.documents;
      })
     .catch((error) => {
        console.log(error);
      }),
  });
};


I have useDocuments in one of my react components but I need to know only when the data changes or is refetched and then setState for another variable. How can I do this?
Was this page helpful?