# NgRx Entity

* **Part of NgRx**
* **Converts arrays to dictionaries**
* **Supports relationships between stores**
* **Super fast find by id**
* **Entity enrichment**
  * **Loading, error, etc**
* **Selectors to transform data back to arrays**

## Entity State

```typescript
interface EntityState<V> {
  ids: string[] | number[];
  entities: { [id: string | id: number]: V };
}
```

## Reducers

{% embed url="<https://stackblitz.com/edit/advanced-ngrx-2-entity?file=src%2Fapp%2Fusers%2Freducers%2Fuser.reducer.ts&view=editor>" %}

## Selectors

* **Memoized**
* **Composable**
* **Testable**

{% embed url="<https://stackblitz.com/edit/advanced-ngrx-2-entity?file=src%2Fapp%2Fusers%2Findex.ts&view=editor>" %}

{% hint style="info" %}
Refactor Tour of Heroes NgRx project to use entity:  <https://stackblitz.com/github/jessesanders/tour-of-heroes/tree/ngrx>
{% endhint %}


---

# 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://briebug.gitbook.io/ngrx-workshop/ngrx-libraries/ngrx-entity.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.
