> For the complete documentation index, see [llms.txt](https://cbwire.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cbwire.ortusbooks.com/v2-1/essentials/lifecycle-events.md).

# Wire Lifecycle

Everything that has a beginning has an end. - The Oracle, Matrix

## Order of Operations

When a [Wire](https://cbwire.ortusbooks.com/v2-1/essentials/creating-components.md) is initially loaded (before any background AJAX requests are performed), the Lifecycle Methods are executed in the following order.

1. onMount()
2. Render [Computed Properties](https://cbwire.ortusbooks.com/v2-1/essentials/computed-properties.md)
3. onRender() or implicit [Template](https://cbwire.ortusbooks.com/v2-1/essentials/templates.md) rendering

For background AJAX requests, lifecycle methods are executed in this order.

1. onHydrate\[DataProperty]\()
2. onHydrate()
3. Render [Computed Properties](https://cbwire.ortusbooks.com/v2-1/essentials/computed-properties.md)
4. Execute [Actions](https://cbwire.ortusbooks.com/v2-1/essentials/actions.md)
5. onRender() or implicit [Template](https://cbwire.ortusbooks.com/v2-1/essentials/templates.md) rendering

## onMount

Runs only **once** when the Wire is initially wired.&#x20;

{% hint style="warning" %}
This does not fire during subsequent renderings for the Wire.
{% endhint %}

```javascript
component extends="cbwire.models.Component" {

    data = {
        "taskId": 0
    };

    function onMount( event, rc, prc, parameters ){
        data.taskId = event.getValue( "taskId" );
    }

}

```

{% hint style="warning" %}
onMount() replaces what was formerly mount(). The mount() method is deprecated and will be removed in future major releases of CBWIRE.
{% endhint %}

## onHydrate

Runs on subsequent requests, after the Wire is hydrated, but before [Computed Properties](https://cbwire.ortusbooks.com/v2-1/essentials/computed-properties.md) are rendered, before an [Action](https://cbwire.ortusbooks.com/v2-1/essentials/actions.md) is performed, or before onRender() is called.

```javascript
component extends="cbwire.models.Component" {

    data = {
        "hydrated": false
    };

    function clicked() {}

    function onHydrate( data ) {
        // Note that computed properties are not rendered yet
        data.hydrated = true;
    }

    function onRender( args ) {
        return "
            <div>
                <div>Hydrated: #args.hydrated#</div>
                <button wire:click='clicked'>Click me</button>
            </div>
        ";
    }
}
```

## onHydrate\[ DataProperty ]

Runs on subsequent requests, after a specific [Data Property](https://cbwire.ortusbooks.com/v2-1/essentials/properties.md) is hydrated, but before [Computed Properties](https://cbwire.ortusbooks.com/v2-1/essentials/computed-properties.md) are rendered, before an [Action](https://cbwire.ortusbooks.com/v2-1/essentials/actions.md) is performed, or before onRender() is called.

```javascript
component extends="cbwire.models.Component" {

    data = {
        "count": 1
    };

    function onHydrateCount( data ) {
        // Note that computed properties are not rendered yet
        data.count += 1;
    }  
}
```

## onRender

Runs during the rendering of a [Wire](https://cbwire.ortusbooks.com/v2-1/essentials/creating-components.md). If onRender() is defined on the Wire, CBWIRE will use what is returned as the component's template, otherwise it will perform a lookup for a view template. The `args` parameter is provided which contains both the [Data Properties](https://cbwire.ortusbooks.com/v2-1/essentials/properties.md) and any rendered [Computed Properties](https://cbwire.ortusbooks.com/v2-1/essentials/computed-properties.md).

```javascript
component extends="cbwire.models.Component" {

    data = {
        "rendered": true
    };
    
    computed = {
        "currentDate": function() {
            return now();
        }
    }

    function onRender( args ) {
        return "
            <div>
                <div>Rendered: #args.rendered# at #args.currentDate#</div>
            </div>
        ";
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cbwire.ortusbooks.com/v2-1/essentials/lifecycle-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
