Xhino Agalliu
Xhino Agalliu

Reputation: 23

Show a loader during timeout? React

I have this code

return function (dispatch) {
    console.log("\t dispatch");
    var timeoutID = setTimeout(function () {
        // rest of code here
        console.log("setTimeout 5 secondi");
    }, 3000);
}

I wanted to ask,is it possible to add logic while timeout? For example ,show a loader while doing timeout? Thank you

Upvotes: 1

Views: 2261

Answers (1)

Zoli Szabó
Zoli Szabó

Reputation: 4534

Do you mean showing the loader before calling setTimeout() and hiding it in the callback of setTimeout()?

return function (dispatch) {
    console.log("\t dispatch");
    showLoader(); // here you can display some graphic
    var timeoutID = setTimeout(function () {
        // rest of code here
        console.log("setTimeout 5 secondi");
        hideLoader(); // hide the loader graphic after 5 seconds
    }, 5000);
}

Upvotes: 2

Related Questions