Skip to content
Advertisement

I am learning Redux thunk by using createAsynThunk. I try to delete an item in todoState but it doesn’t work and i don’t know the reason

My slices file filename: slices.ts

JavaScript

My action creators. filename: actioncreators.ts

JavaScript

Todo interface, filename: Todo.ts

JavaScript

I run my index file, filename: index.ts

JavaScript

I expect it would be

JavaScript

But actually it is.

JavaScript

Advertisement

Answer

Your code is fine. The reason you are getting the same result after delete is because you have wait in your delete handler. In the mean time, when wait is going on, your next statement executes (concept of call stack & task queue) which give the same result.

To validate this, add wait for the second console.log and you’ll see the updated results.

Following is the link to the stackblitz template having your code: stackblitz

console.log result

Read more about JavaScript’s Task queue & call stack call stack & event look

Hope that answers your doubts.

Thanks, Manish

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement