# 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.

```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.

```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.

```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](/docs/platform/aura-platform/guide/js-client-side-controller.md)
- [Handle the render Event](/docs/platform/aura-platform/guide/js-render-handler.md)
- [Component Attributes](/docs/platform/aura-platform/guide/components-attributes.md)
- [Detecting Data Changes with Change Handlers](/docs/platform/aura-platform/guide/js-cb-data-change.md)
