getCallback()

Use $A.getCallback() to wrap any code that modifies a component outside the normal rerendering lifecycle, such as in a setTimeout() call. The $A.getCallback() call ensures that the framework rerenders the modified component and processes any enqueued actions.

Don’t use $A.getCallback() if your code is executed as part of the framework’s call stack. For example, your code is handling an event or in the callback for an Apex controller action.

Run async operations with a $A.getCallback() wrapper. For example, use setTimeout() and setInterval() with $A.getCallback(). Use Promise resolve or reject handlers with $A.getCallback().

When using $A.getCallback(function callback) with a Promise, the function runs after the Promise resolves. For example:

getCallback (function callback)

callback: Type: function. The method to call after establishing an Aura context.

Use $A.getCallback() with component validity check.

Use Promise handling with Aura lifecycle management.

See Also