Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redux Toolkit · Type Alias

EntityState

EntityState<T> is the normalized Redux Toolkit state shape for a collection of entities of type T. It keeps entity IDs in ids and records in the entities lookup.

How it works

EntityState<T> is the TypeScript shape used for a normalized collection of entities of type T. It stores entity identifiers in ids and the corresponding records in entities, and is commonly obtained or initialized through createEntityAdapter.

Syntax

export interface EntityState<T> {
  ids: EntityId[]
  entities: Record<EntityId, T>
}

Parameters

NameTypeDescription
TType parameterThe entity type stored in the normalized collection.

Returns

A normalized entity-state object with ids and entities fields.

Key points

  • EntityState is generic: T specifies the type of every stored entity, while ids stores their identifiers.
  • createEntityAdapter returns an adapter object that works with the normalized EntityState shape.
  • The adapter provides getInitialState to create the initial normalized state.
  • The state models a collection whose records share one entity type.
  • Adapter operations can populate the state from either entity arrays or ID-keyed records, with setAll replacing the collection.

Common mistakes

  • The ids collection contains EntityId values, so an entity's identifier type must match the adapter's identifier configuration.

Example: Typing normalized entity state

import { createEntityAdapter, type EntityState } from '@reduxjs/toolkit'

type Todo = { id: string; text: string; completed: boolean }
type TodosState = EntityState<Todo>

const todosAdapter = createEntityAdapter<Todo>()
const initialState: TodosState = todosAdapter.getInitialState()

console.log(initialState)

This creates a normalized entity state whose item type is Todo, then initializes it through the adapter.

When to use it

Normalized CRUD collections

A slice stores many records that are frequently added, updated, or removed by ID.

ID-based lookups

Selectors need efficient access to individual records and the complete collection.

Strongly typed entity state

A TypeScript slice needs an explicit state type for adapter-managed data.

Interview questions

QWhat does EntityState<T> represent?

EntityState<T> represents normalized collection state for entities of type T. Its core fields are ids, an ordered list of identifiers, and entities, a lookup keyed by those identifiers.

Follow-up: Why normalize instead of storing an array? A lookup map avoids duplicating records and lets generated adapter operations update entities by ID.

QWhat fields make up an EntityState?

The type has an ids array and an entities record. The adapter uses that structure to provide CRUD reducers and selectors for the collection.

Follow-up: How is the empty state created? Call the adapter's getInitialState method rather than manually assembling the shape, especially when adding extra slice fields.

QHow does EntityState relate to createEntityAdapter?

EntityState is typically used with createEntityAdapter. The adapter generates reducers for adding, replacing, updating, and removing entities, plus selectors for reading normalized data.

Follow-up: What can setMany accept? It accepts either an array of entities or a Record<EntityId, T> object.

  • createEntityAdapter
  • EntityId
  • getInitialState
  • addOne
  • addMany
  • setAll
  • removeOne
  • removeAll

Source: createEntityAdapter. Checked 2026-10-15.