TanStackT
TanStackโ€ข17mo agoโ€ข
22 replies
faint-white

How to compare previous vs updated data?

Using Query inside a custom hook in a React Native/Expo app. A bit new to React Query so wanted to know best practices to manage this.

import { useQuery } from "@tanstack/react-query";

export function useLiverunsData() {
  return useQuery({
    queryKey: ["liveruns"],
    queryFn: () => fetch("/api/liveruns").then((res) => res.json()),
    refetchInterval: 5000,
    staleTime: 5000,
  });
}


Each object in the response contains a worldId which acts as the unique key.
I want to compare the previous JSON to the new JSON, so I can identify which items have been removed/added and write animations in regards to them appearing and disappearing.

What would be the best way to approach this? Thank you in advance :peepoHappy:
Was this page helpful?