createEntityAdapter

function
entity/entityAdapter.ts:163
signature
createEntityAdapter<T, Id>(options): EntityAdapter<T, Id>

Builds an adapter for one entity type.

Type parameters

NameTypeDescription
T
Idextends EntityId

Parameters

NameTypeDescription
optionsEntityAdapterOptions<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') });