Javascript 在超时期间显示加载程序?反应
我有这个密码Javascript 在超时期间显示加载程序?反应,javascript,reactjs,settimeout,Javascript,Reactjs,Settimeout,我有这个密码 return function (dispatch) { console.log("\t dispatch"); var timeoutID = setTimeout(function () { // rest of code here console.log("setTimeout 5 secondi"); }, 3000); } 我想问,超时时是否可以添加逻辑? 例如,在执行超时时显示加载程序? 谢谢您的意思是在调用se
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);
}