2016-09-07 53 views
0

我有這樣的代碼超時時顯示加載程序?反應

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

我想問問,是不是可以添加邏輯,而超時? 例如,在超時時顯示加載器? 謝謝

回答

2

您的意思是在致電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); 
}