unwanted invalidations despite set query key
Hello everyone,
I am currently struggeling with understanding why cache invalidations happen.
react-query v5.55
Setup: Query Client wrapped around entire App.
defaultOptions: staleTime 30min, gcTime: 60min, cacheTime: 60min (for testing), refetchOn Win false, OnMount false, OnReconnect false.
cache keys are for simple lists like "artworks", "locations", "contacts". There is no other fluff.
Issue: Whenever I use my useCreateObject hook which is supposed to invalidate an exact cache onSuccess and get redirected via useNavigate from react-router-dom, to a specified page, all listed fetch requests on the destination page get invalidated.
upon invalidateQueries([key]) all QueryStates get invalidated: true and fetching: true
1 Reply
correct-apricotOP•9mo ago
How I use the generic ones:
export const useFetchArtworks = () => useFetch("artworks", ARTWORKS_LIST_CREATE);
export const useCreateArtwork = () => useCreateObject2("artworks", ARTWORKS_LIST_CREATE);
const createArtwork = useCreateArtwork();
createArtwork.mutate(data)
Side note: Normal routing does not break the cache.