Have you try to use "enabled" option of "useQuery"? It is only fetch data when meet certain condition and prevent redundant API call.