# onChange hook

This hook might be used for many use cases. One of them to update the view after state was changed if you are not using:

* actions&#x20;
* async pipes

for example:

```
Selected location: {{ location }}
```

```typescript
location: any;

constructor(private store: Store<any>, private cd: ChangeDetectorRef) { }

ngOnInit() {
    this.filters = new FormGroup({
        condition: new FormGroup({
            new: new FormControl(false),
            used: new FormControl(false),
            notSpecified: new FormControl(false)
        }),
        location: new FormControl()
    });

    this.store.select(['form', 'location']).subscribe(state => this.location = state);

    this.ngFormStateManager = this.store.select(['form'])
        .form.bind(this.filters)
        .shouldUpdateState((params: ShoulUpdateStateParams) => true)
        .onChange(state => // Do something with changes);
}
```

{% hint style="info" %}
This event will not be triggered if you are updating form state from the code manually
{% endhint %}

This becomes handy for example when you want to change one state property value depending on another change. For this you can do following:

```typescript
const ngFormStateManager = this.actions.store.form
    .bind(this.form, { emitEvent: true, onChangePairwise: true })
    .onChange(([prev, curr]) => {
        if (prev.monthlyIncome !== curr.monthlyIncome) {
            this.recalculateQuarterIncome(curr.monthlyIncome!);
        }

        if (prev.quarterIncome !== curr.quarterIncome) {
            this.recalculateMonthlyIncome(curr.quarterIncome!);
        }
    });
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vytautas.gitbook.io/ng-state/core-concepts/store/form-manager-plugin/onchange-hook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
