---
schema_version: "1"
id: 9fee5e93d9cb809bf3152820986be70b4b76536c4da174cd97b050214f080f8b
title: Invoking Actions on Component Initialization
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-init-handler.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/js-cb-init-handler.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 92b3c682a1af9987c75889e8d5125b1b87996a6019a2434c394e27afd263aa63
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Invoking Actions on Component Initialization

Use the `init` event to initialize a component or fire an event after component construction but before rendering.

**note:** The `init` event is fired only once per lifecycle of the component. The `init` event doesn’t get fired if the component is served from cache. To execute JavaScript code every time a component is rendered, use the `render` event instead.

Let’s look at an example.

<!-- otherprops: set_clipboard -->
```nolang
<!--initCmp.cmp-->
<aura:component>
    <aura:attribute name="setMeOnInit" type="String" default="default value" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <p>This value is set in the controller after the component initializes and before rendering.</p>
    <p><b>{!v.setMeOnInit}</b></p>
    
</aura:component>

```

The magic happens in this line.

<!-- otherprops: set_clipboard -->
```nolang
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
```

This code registers an `init` event handler for the component. `init` is a predefined event sent to every component. Setting `value="{!this}"` marks this as a value event. You should always use this setting for an `init` event.

After the component is initialized, the `doInit` action is called in the component’s controller.

<!-- otherprops: set_clipboard -->
```javascript
// initCmp.js
({
    doInit: function(cmp) {
        // Set the attribute value. 
        // You could also fire an event here instead.
        cmp.set("v.setMeOnInit", "controller init magic!");
    }
})
```

The `doInit` action sets an attribute value, but it could do something more interesting, such as firing an event.

If a component is contained in another component or app, the inner component is initialized first.

**See Also**  


-   [Handling Events with Client-Side Controllers](https://developer.salesforce.com/docs/platform/aura-platform/js/js-client-side-controller.md)
-   [Handle the render Event](https://developer.salesforce.com/docs/platform/aura-platform/js/js-render-handler.md)
-   [Component Attributes](https://developer.salesforce.com/docs/platform/aura-platform/components/components-attributes.md)
-   [Detecting Data Changes with Change Handlers](https://developer.salesforce.com/docs/platform/aura-platform/guide/js-cb-data-change.md)

