在超时期间显示加载程序?反应

Show a loader during timeout? React

本文关键字:程序 反应 加载 显示 超时      更新时间:2023-09-26

我有这样的代码

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

我想问,是否有可能在超时时添加逻辑?例如,在执行超时时显示加载程序?谢谢你

您的意思是在调用setTimeout()之前显示加载器并将其隐藏在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);
}