setTimeout in Lightning Component [AURA]

I found it very important as many places, JS functions can save your a**. I mean LIFE. But specially setTimeout function when you need to perform some function after specific time.

Here is an example to use JS setTimeout function in AURA Component,

1. If set timeout modifies any attributes, use $A.callback-

     $A.getCallback(function() {
          helper.hideSpinner(component, helper)
     }), 500

2. As per setTimeout documentation, use any one of the following if calling function doesn’t modifies any attributes:

window.setTimeout(function(){ helper.hideSpinner(component, helper)}, 500);
// or
window.setTimeout(helper.hideSpinner, 500, component, helper);


Leave a Comment