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?2 Replies
stormy-gold•3y ago
put id in the key!!
it's documented
I have at least 3 blogpost mentinoning this
we have an eslint rule that can spot those mistakes
what else shall we do 🤷♂️
metropolitan-bronzeOP•3y ago
Damn.. sorry about that, i didnt notice it
Eitherway, adding the id in the key helped
Thank you very much