What is an async thunk?

JavaScript

Async Thunk

It is a function that doesn't need any arguments passed to it to do it's job, except you need to pass it a callback so that you can get the value out.

function addAsync(x, y, cb) {
setTimeout(function () {
cb(x + y);
}, 1000);
}

var thunk = function (cb) {
return addAsync(10, 15, cb);
};

thunk(function (sum) {
console.log(sum); // 25
});
00:00

Table of Contents