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

Redux Toolkit · Module

adapter.getSelectors

adapter.getSelectors generates memoized selectors for a normalized entity state. An optional input selector lets those selectors accept the complete Redux state instead of the entity state directly.

How it works

getSelectors creates memoized selectors for an entity adapter. With no argument, the selectors expect the entity state itself; with an input selector, they accept the complete Redux state and locate the entity slice before reading IDs, entities, totals, or individual items.

Syntax

adapter.getSelectors<RootState>(selectState?)

Parameters

NameTypeDescription
selectState(rootState) => entityStateOptional selector from the root Redux state to the adapter's entity state. Omit it when selectors should receive the entity state directly.

Returns

A set of memoized selectors: selectIds, selectEntities, selectAll, selectTotal, and selectById. They are either unglobalized selectors over the entity state or root-state-aware selectors when given an input selector.

Key points

  • getSelectors is a method on an entity adapter that generates the standard selector set for its normalized entity state.
  • selectIds exposes the normalized state's ordered ID array.
  • selectEntities exposes the ID-to-entity lookup object.
  • selectAll produces an entity array by following the IDs array, preserving its order.
  • selectTotal reports the collection size.
  • selectById looks up one entity by ID and yields undefined when the ID is absent.

Common mistakes

  • Root-state selectors need an input selector that points to the adapter's entity state; otherwise, use the unglobalized selectors with the entity state directly.
  • Calling getSelectors without an input selector does not produce selectors for the whole Redux store.

Example: Generate root-state selectors

import { createEntityAdapter, createSlice } from '@reduxjs/toolkit'

type Book = { id: string; title: string }
type RootState = { books: ReturnType<typeof booksSlice.reducer> }

const booksAdapter = createEntityAdapter<Book>()
const booksSlice = createSlice({
  name: 'books',
  initialState: booksAdapter.getInitialState(),
  reducers: booksAdapter.getReducers(),
})

export const { selectAll, selectById, selectTotal } =
  booksAdapter.getSelectors<RootState>((state) => state.books)

const titles = selectAll({ books: { ids: ['b1'], entities: { b1: { id: 'b1', title: 'Redux' } } } }).map((book) => book.title)
console.log(titles)

Creates root-state-aware selectors for the normalized books slice, then uses selectAll to retrieve entities in stored ID order.

When to use it

Read normalized collections

A slice stores entities using createEntityAdapter and components need all records, one record, IDs, or the count.

Globalize selectors for a slice

The adapter's entity state is mounted under a known slice in the root store.

Select nested entity state

The normalized entity state is nested below another store branch, such as cached data.

Interview questions

QWhat does adapter.getSelectors return?

It returns memoized selectors for an entity state: selectIds, selectEntities, selectAll, selectTotal, and selectById. The selectors read the normalized IDs and entity lookup table.

Follow-up: How do the selectors become root-state aware? Pass a selector that accepts the entire Redux state and returns the relevant entity state.

QWhen should getSelectors receive an input selector?

Call getSelectors with no argument when the selector input is already the entity state. Pass an input selector such as state => state.books when selectors should receive the root Redux state.

Follow-up: What changes if the entity state is nested in an RTK Query cache? Supply an input selector that reaches the normalized data inside that cache state.

QWhat do the generated selectors read and return?

selectAll returns entities in the order represented by the state's ids array, while selectById accepts an entity ID and returns that entity or undefined. selectTotal reports the number of stored entities.

Follow-up: Which normalized structures do these selectors rely on? They read the ids array and entities lookup table maintained by the adapter.

  • createEntityAdapter
  • selectIds
  • selectEntities
  • selectAll
  • selectTotal
  • selectById

Source: createEntityAdapter. Checked 2026-10-15.