Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle the loader in a common way(middleware) using RTK Query?

I am new to RTK queries, and I like to work with RTK queries.

In my project, I would like to add a common loader where if any request is running show the page loader and once the response comes back either success or failure, I would like to hide the loader.

Please let me know if anyone has more context on this.

Thanks in Advance.

like image 714
Anji Avatar asked Dec 31 '25 16:12

Anji


1 Answers

Right now, nothing like that is implemented out of the box - but of course, the data is all available in the Redux store.

So you can probably do something like (pseudocode, check with the devtools if I have all the data structures right here, I can't look it up right now)

const isAnythingLoading = useSelector(state => Object.values(state.api.queries).some(entry => entry.status == 'loading'))
like image 145
phry Avatar answered Jan 04 '26 20:01

phry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!