# Lifecycle hooks

There are several lifecycle hooks available for you to subscribe to and perform various actions in response to events.

These lifecycle hooks can be defined on the JSF definition as such:

```
$lifeCycle?: {
  $beforeFormInit?: {
    $eval: string;
  };
  $afterFormInit?: {
    $eval: string;
  };
  $beforeFormDestroy?: {
    $eval: string;
  }
  $afterFormDestroy?: {
    $eval: string;
  },
  $onFormValueChange?: {
    $eval: string;
  },
  $onFormStatusChange?: {
    $eval: string;
  }
};
```

\
List of available lifecycle hooks:

| Lifecycle hook      | JSF lifecycle property | Description                                                                                                                                                                                                                                                                                                                    |
| ------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Before form init    | $beforeFormInit        | <p>Called before the JSF builder instance is created which allows you to modify the document or builder options. Provides two eval context variables:</p><ul><li><code>$doc</code> JSF document</li><li><code>$options</code>Builder options</li></ul>                                                                         |
| After form init     | $afterFormInit         | <p>Called after the JSF builder instance was created. Note that the Angular layout </p><p>omponents have not yet been created at this stage. </p>                                                                                                                                                                              |
| Before form destroy | $beforeFormDestroy     | Called before the JSF builder instance is about to be destroyed, due to the Angular jsf doc component being destroyed or otherwise.                                                                                                                                                                                            |
| After form destroy  | $afterFormDestroy      | Called after the JSF builder instance has been destroyed.                                                                                                                                                                                                                                                                      |
| Form value change   | $onFormValueChange     | <p>Called every time a form property's value changes. Provides two additional eval context variables: </p><ul><li><code>$path</code> Path of changed prop</li><li><code>$data</code> An object containing the information about the change</li></ul>                                                                           |
| Form status change  | $onFormStatusChange    | <p>Called every time a form's property state changes (valid, invalid, disabled, ...). Provides two additional eval context variables:</p><ul><li><code>$from</code> An object containing information about the changed prop path</li><li><code>$data</code> An object containing information about the status change</li></ul> |
