TanStackT
TanStack3y ago
3 replies
wispy-olive

useQuery - isLoading state not triggered

I have a Vite + React application. I fetch the todo data based on the page URL
id
param (example /my-todos/1 , /my-todos/2 etc.)
When I switch from the /my-todos/1 to /my-todos/2, the isLoading state stays
false
and I still see the old todo list for a split second.

Currently I fetch data as such:
const { data, isLoading, isError, error } = useQuery({ queryKey: ["todos"], queryFn: () => getOneTodoList(id!), });

How do I fix this issue?
Was this page helpful?