# 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 %}
