question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with aborting createAsyncThunk

See original GitHub issue

Hey everyone, I’ve been using RTK for a while now with no real issues and love where the library is going. Recently I ran into my first need to actually abort a call and tried following the docs however I ended up getting an runtime error saying that Uncaught TypeError: promise.abort is not a function. I’m on version 1.5.0.

I’m not sure what i could be doing wrong as my code looks like this and follows the tutorial.

const promise = dispatch(
      asnycThunkCall({
        productId: "id",
      }),
    );
  return () => {
    promise.abort();
  };

My dispatch is also setup like

export type AppDispatch = typeof store.dispatch;
export const useAppDispatch = () => useDispatch<AppDispatch>();

I tried printing out the promise returned from the dispatch and I didn’t see an abort function but I don’t know how reliable that is. Any tips?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Shannorcommented, Feb 6, 2021

@msutkowski Hmm let me try that. You are correct that I couldn’t recreate in the CSB. It worked on there with the same setup. So something must be off with my versions or modules. Thanks let me try that.

0reactions
Shannorcommented, Feb 6, 2021

That’s fair. I did your above changes and things are working now as expected. I’ll play around more to see if I can better fine tune it. Thanks again for the help I really appreciate it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

redux toolkit - Abort is not working for createasyncthunk in react
How to abort the Action Abort is not working for createasyncthunk in react. How can I abort any action of createAsyncThunk?
Read more >
How do i cancel a createAsyncThunk action which calls an api?
Calling thatPromise.abort() will at least cancel dispatching actions, but doesn't do anything to cancel the actual request by itself. However, ...
Read more >
10 - Canceling thunks while running - redux toolkit - YouTube
In this series, we'll be going through the createEntityAdapter API and use it with createAsyncThunk playlist: In this series, we'll be going ...
Read more >
reduxjs/toolkit - NPM Package Overview - Socket.dev
This bugfix release fixes assorted issues that were reported with RTK ... Calling promise.abort() on a createAsyncThunk promise before an ...
Read more >
createAsyncThunk.ts - UNPKG - @reduxjs/toolkit
@reduxjs/toolkit/src/createAsyncThunk.ts ... @ts-ignore we need the import of these types due to a bundling issue. ... 164, abort(reason?: string): void.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found