'react query is not working cache. althogh i add option staleTime: Infinity

i try react query. but, it is not working cache..

i tried this :

const getTags = async (): Promise<tagRes> => {
  const jwtToken = getJWTToken("token");
  if (jwtToken) {
    const config = {
      headers: {
        Authorization: `Bearer ${jwtToken}`,
      },
    };

    const { data } = await instance.get("/api/user/myhashtags", config);
    return data;
  } else {
    const { data } = await instance.get("/api/user/myhashtags");
    return data;
  }
};


useQuery<tagRes, Error | void>("getTag", getTags, { staleTime: Infinity });

when i reload or go back to other page. i expect it call once. However, whenever i reload or comeback, always call api

Why is React Query not using the cache? Am i doing something wrong?

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source