createEntityAdapter
functionsignature
createEntityAdapter<T, Id>(options): EntityAdapter<T, Id>Builds an adapter for one entity type.
Type parameters
| Name | Type | Description |
|---|---|---|
T | — | |
Id | extends EntityId |
Parameters
| Name | Type | Description |
|---|---|---|
options | EntityAdapterOptions<T, Id> |
Returns
EntityAdapter<T, Id>
Example
example
const todos = createEntityAdapter<Todo>();
const spec: ReducerSpec<EntityState<Todo>, EM> = {
state: todos.getInitialState(),
when: { keys: eventKeys<EM>()([['todos', 'toggled']]) },
reducer: (state, event) =>
todos.updateOne(state, { id: event.payload.id, changes: { done: event.payload.done } }),
};
// and in a component
useAtomicProp({ reducer: 'todos', property: todos.pathTo(id, 'title') });