Search code examples
javascriptreactjsreduxredux-toolkitrtk-query

How to get isLoading / isFetch on auto-refresh in RTK Query?


For example, the API has the getList() and deleteItem() functions. providesTags is configured to requery: after a deleteItem() request, a getList() request is automatically fired.

It is necessary to block the interface while the getList() request is in progress. How to do it?

I usually do this with isLoading, but it is part of a hook called on the component. And in the case of automatic re-request, the call occurs not in the component, but in the store


Solution

  • first, I miss understood your question I think somehow you managed to call getList inside of the store. you don't have access to the loading inside of the store because you have access to isLoading inside of Component, right?

    first why you should do such a thing and if you must do it please provide some codes or explain more.

    second I am assuming you do something like this dispatch(api.endpoints.getPost.initiate()) then if so you should know RTK query have something called Matchers. and throw this you have access to actions like matchPending, matchFulfilled and matchRejected.