---
schema_version: "1"
id: a4576896a170a6dbbce267c4b52446492b35c8f4edbf4b4f2c7f9bc72b372f46
title: Modifying Components Outside the Framework Lifecycle
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/js-cb/js-cb-mod-ext-js.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/js-cb-mod-ext-js.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5c8c31f6f89a860493615c04ee766b25dbf2633ece95225c7bd863f266d5e562
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Modifying Components Outside the Framework Lifecycle

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.

**note:** `$A.run()` is deprecated. Use `$A.getCallback()` instead.

You don't need to 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 a server-side controller action. An exception is when you want to pass the callback to Lightning Data Service, such as when you are creating a record using `force:recordData`. If the callback is passed in without being wrapped in `$A.getCallback()`, any attempt to access private attributes of your component results in access check failures.

An example of where you need to use `$A.getCallback()` is calling `window.setTimeout()` in an event handler to execute some logic after a time delay. This puts your code outside the framework's call stack.

This sample sets the `visible` attribute on a component to `true` after a five-second delay.

<!-- otherprops: set_clipboard -->
```javascript
window.setTimeout(
    $A.getCallback(function() {
        cmp.set("v.visible", true);
    }), 5000
);
```

Note how the code updating a component attribute is wrapped in `$A.getCallback()`, which ensures that the framework rerenders the modified component.

**note:** You don't need a `cmp.isValid()` check within this `setTimeout()` call as the `cmp.set()` call doesn't do anything when the component is invalid.

**warning:** Don't save a reference to a function wrapped in `$A.getCallback()`. If you use the reference later to send actions, the saved transaction state will cause the actions to be aborted.

**See Also**  


-   [Creating a Record](https://developer.salesforce.com/docs/platform/aura-platform/data-service/data-service-create-record.md)
-   [Handling Events with Client-Side Controllers](https://developer.salesforce.com/docs/platform/aura-platform/js/js-client-side-controller.md)
-   [Checking Component Validity](https://developer.salesforce.com/docs/platform/aura-platform/js/js-cmp-isvalid.md)
-   [Firing Events from Non-Aura Code](https://developer.salesforce.com/docs/platform/aura-platform/events/events-external.md)
-   [Communicating with Events](https://developer.salesforce.com/docs/platform/aura-platform/events/events-intro.md)

