Skip to content

Is it possible to force a network operation with listenerApi.dispatch() of a query's initiate(): #4980

Answered by steinarb
steinarb asked this question in Q&A
Discussion options

You must be logged in to vote

Figured out how to do it:

  1. Introduced a new tag in the query I wanted reloaded:
     endpoints: (builder) => ({
         ...
         getAccount: builder.query({ query: username => '/account/' + username, providesTags: ['PaymentMade', 'JobEdit'] }),
         ...
    
  2. In the listener, instead of trying to start a query, I dispatch an action that invalidates the tag:
    listeners.startListening({
        matcher: api.endpoints.getNotification.matchFulfilled,
        effect: (action, listenerApi) => {
            const notifications = action.payload;
            if (notifications.length) {
                const notification = notifications[0];
    
                if (notification.message) {
                    // Update the balance after payme…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by steinarb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant