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

Redux Toolkit · Module

adapter.getInitialState

adapter.getInitialState creates a normalized entity state with ids and entities. It can merge additional slice fields and optionally populate the state with initial entities.

How it works

The adapter method creates a fresh normalized state with empty ids and entities collections. You can merge extra state fields into it and optionally provide initial entities, either as an array or an ID-keyed record, so the result is ready for a slice or adapter operations.

Syntax

getInitialState(): EntityState<T>
getInitialState<S extends object>(state: S): EntityState<T> & S
getInitialState<S extends object>(state: S, entities: T[] | Record<EntityId, T>): EntityState<T> & S

Parameters

NameTypeDescription
stateS extends objectOptional additional state fields to merge into the normalized entity state.
entitiesEntity[] | Record<EntityId, T>Optional entities used to pre-populate the returned state; the documentation shows an entity array or Record<EntityId, T>.

Returns

A new EntityState<T>; when additional state is supplied, the result is EntityState<T> & S. With preloaded entities, the returned normalized state contains those entities.

Key points

  • Calling the method produces a fresh empty normalized state with ID and entity collections.
  • An optional state object lets the slice carry metadata alongside its normalized entities.
  • Extra fields become properties of the resulting state while the adapter-managed collections remain available.
  • Initial entities can be provided as either a list or an ID-keyed record.

Common mistakes

  • Properties supplied in the additional state object are merged into the normalized state; they do not replace its core collections.
  • When pre-populating, use an entity array or an ID-keyed record rather than an unrelated collection shape.

Example: Create normalized initial state

import { createEntityAdapter } from '@reduxjs/toolkit'

type Book = { id: string; title: string }

const booksAdapter = createEntityAdapter<Book>()

const initialState = booksAdapter.getInitialState(
  { status: 'idle' },
  [
    { id: 'a', title: 'First' },
    { id: 'b', title: 'Second' },
  ],
)

console.log(initialState.ids)
console.log(initialState.status)

Creates normalized book state, adds a status field, and pre-populates the entity collection.

When to use it

Slice initialization

Define a slice's normalized starting state while keeping loading or error metadata beside entity data.

Pre-populated collections

Provide seed data to an adapter-backed state before reducers process later updates.

Normalized fallback state

Create an empty normalized fallback state for selectors or data transformation workflows.

Interview questions

QWhat does adapter.getInitialState() return?

It returns a new normalized entity-state object whose base shape is {ids: [], entities: {}}. The method is useful as a slice's initial state and can also include extra fields.

Follow-up: How would you initialize loading metadata together with entities? Call getInitialState({status: 'idle', error: null}); the supplied metadata is merged with the normalized fields.

QHow do you add non-entity fields to the initial state?

The first argument can be an object containing additional state fields. Those fields are merged into the returned entity state, allowing metadata such as loading status to live beside ids and entities.

Follow-up: Can it start with entities too? Yes. Supply an entity array or an ID-keyed record as the optional preloaded entities argument.

QHow can the initial state be pre-populated?

The method supports an overload with an additional state object and an entities argument. The entities may be an array or a Record<EntityId, T>, producing a normalized initial collection.

Follow-up: Why use this instead of manually constructing ids and entities? The adapter applies its entity identity and normalization rules consistently, reducing hand-written setup.

  • createEntityAdapter
  • EntityState
  • addMany
  • getSelectors

Source: createEntityAdapter. Checked 2026-10-15.