-1

I'm using RTK Query and have hit a snag with onQueryStarted, in particularly with the api.util object. Here's the endpoint:

sendLogout: builder.mutation({
            query: () => ({
                url: '/auth/logout',
                method: 'POST'
            }),
            async onQueryStarted(arg, {dispatch, queryFulfilled}) {
                console.log("onquerystarted")
                try {
                    await queryFulfilled
                    dispatch(logOut())
                    dispatch(api.util.resetApiState())
                } catch (err) {
                    console.log(err)
                }
            }
        }),

This works fine on my localhost, however I get a reference error that api is undefined. As far as I can tell from the docs, there is no need to declare it. Now, without declaring it, when I go to build the image for the app, it fails since the reference error is being thrown. I tried declaring api in the args for onQueryStarted- (arg, api, {dispatch, queryFulfilled}), but then this throws a _ref3 is undefined error. The error does not show up in eslint, so I cannot just tell it to ignore the error, which I tried anyway...

I'm curious if anyone else has come across this and has a solution. Since its not declared in the docs, and since I cannot find anyone else asking it, perhaps there's something else I missed that would resolve it. Thanks

Jowz
  • 399
  • 1
  • 3
  • 16

0 Answers0