React Query - useIsFetching & useIsMutation

Full Stack Developer and JavaScript and TypeScript enthusiastic.
Search for a command to run...

Full Stack Developer and JavaScript and TypeScript enthusiastic.
No comments yet. Be the first to comment.
Hey Folks, In this post, you'll learn how to debug and check whatever happens in your React Query application. It's normal when you begin to learn or use a tool; check the tools around it to understand the developer experience so you can decide wheth...
Today, I wanna show you how to set up your devices with Antigravity using only the agentic mode, without touching any code. At the last CodeMotion Rome, I got my special badge. A CM Node, a special ha

As a developer, you have to take control of your projects every day. Whether it is a company repository, an open source project you maintain or collaborate on, or a simple pet project. Gaining control over your projects often depends on the platform ...

My Antigravity first experience

Write clear and insightful commit messages using AI and GitLens.

We are in the AI era. New models emerge daily, and many applications have already integrated AI into their workflows. Gemini, OpenAI, Copilot, Deepseek, Llama, and many others enable AI in your applications or help you write code, but they all need a...

Hey folks,
Today it is time to talk about two hooks exposed by react query: useIsFetching and useIsMutation.
Each of these hooks could be used to understand if there is a fetching request or if there is a mutation request ongoing in the application.
They are useful if we need to create a global loader that appears when there are one or more requests on going.
But how can you use them?
Let's start with the useIsFetching.
import { useIsFetching } from '@tanstack/react-query';
export default function Loader() {
const isFetching = useIsFetching();
if (!isFetching) return null;
return <>Fetching...</>
}
As you can see, the syntax is pretty simple. You can import the hook from the library and you can use the hook in your components. The hook returns only a boolean value that indicates if there are one or more fetching requests in the application. Then with this data, you can decide if you have to show a loader or not. Easy peasy!
Now it's time to move to the useIsMutation hook. This hook is similar to the previous one, the only different concept is that this hook handles the mutation requests. Let's see an example!
import { useIsMutating } from '@tanstack/react-query';
export default function Loader() {
const isMutating = useIsMutating();
if (!isMutating) return null;
return <>Mutating...</>
}
As you can notice, the syntax is the same as the previous one, the only difference stands in the name of the hook and in its concept.
If you want to find more about these two hooks see my Youtube video about them.
Ok, I think you have an idea of how these two hooks work. I hope you enjoyed this content.
See you soon folks
Bye Bye 👋
p.s. you can find the code of the video here