# Sub States Deprecation

We're planning to remove the option to declare sub-states on the state using the `children` property. This feature was introduced years ago to address certain issues, but it's not technically beneficial and doesn't add any value.

Moreover, this feature has been restrictive because you always had to consider state erasure when calling `ctx.setState` in states that have sub-states. This is because `ctx.setState` removes the sub-state, which is mostly invisible from the parent state.

Therefore, it necessitated maintaining a relationship between a parent and a child state.

It's preferable to have separate states that maintain the relationship. There shouldn't be bidirectional dependencies between states, as it often leads to cyclic dependency errors.

For example, if you have an invoice state and an invoice lines state, instead of tying the invoice lines state to the invoice state through `children: [InvoiceLinesState]`, you can keep `InvoiceLinesState` entirely separate. Each invoice line item may have an `invoiceId` property. Then, when you want to select a list of line items for an invoice, you can join the line items state selector with `InvoiceState.getInvoiceId` or something similar to retrieve the invoice ID, and then filter the invoice lines list by `invoiceId`.


---

# 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://www.ngxs.io/deprecations/sub-states-deprecation.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.
