Displaying loading spinner when uploading image by the user (using 'isLoading' state)
Hii folks! 👋 I'm newbie in TanStack Query and I would have a question related to displaying the loader spinner onThe thing is also that I use a certain hook 'useGetAllImages' where there is an 'allImagesLoading' state which is initially 'false' if I understood correctly. I also call this hook on the page where I want to display the spinner and I tried to call it on the page in the way that I added to my state and then above return if i do this i can display it: but I want this state to be 'false' when fetching the user selected photo, right? If someone could give me some guidance or similar, I would be very grateful :reactcharts: 🔥PhotoUploadercomponent during the process of uploading a certain photo that the user chooses. Namely, I encountered a problem displaying myLoadercomponent when uploading images. When the user selects the input field 'Choose files' and then a specific photo, at that moment I should show my loading spinner and of course hide it when the image is displayed on the screen.
8 Replies
unwilling-turquoise•9mo ago
isPending will be equal to true when the status of a query is pending
status: QueryStatusWill be: pending if there's no cached data and no query attempt was finished yet. error if the query attempt resulted in an error. The corresponding error property has the error received from the attempted fetch success if the query has received a response with no errors and is ready to display its data. The corresponding data property on the query is the data received from the successful fetch or if the query's enabled property is set to false and has not been fetched yet data is the first initialData supplied to the query on initialization.
unwilling-turquoise•9mo ago
useQuery | TanStack Query React Docs
tsx const { data, dataUpdatedAt, error, errorUpdatedAt, failureCount, failureReason, fetchStatus, isError, isFetched, isFetchedAfterMount, isFetching, isInitialLoading, isLoading, isLoadingError, isPa...
unwilling-turquoise•9mo ago
So
allImagesLoading will be true initiallyoptimistic-goldOP•9mo ago
I managed to display the spinner with every refetch of the entire page, but I specifically need it when uploading an image. I was thinking of using this existing hook and its 'isUploadingPhotos' prop, do you think that's ok?

optimistic-goldOP•9mo ago
if I call this prop on the Upload page
I always getting 'false' as value in the log.
and it should become 'true' when the image is uploaded, right?
unwilling-turquoise•9mo ago
Yeah I think you want the loading spinner to track the state of the mutation
optimistic-goldOP•9mo ago
yes
any idea how i could solve it?
unwilling-turquoise•9mo ago
Would you be able to post a codesandbox or stackblitz of an example of your issue?