Q:

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

A:

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);
}

