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

Redux Toolkit · Module

adapter.setAll

adapter.setAll replaces an entity adapter's entire normalized collection with supplied entities. It accepts either an array or an ID-keyed record and is commonly used inside Redux Toolkit slice reducers.

How it works

Call an entity adapter's setAll reducer with the entity state and either an array of entities or an ID-keyed record. It removes the previous collection and stores exactly the supplied entities, using the adapter's ID and ordering rules.

Syntax

adapter.setAll(state, entities)

Parameters

NameTypeDescription
stateEntityState<T, EntityId>The entity state managed by the adapter, typically the draft state passed to a slice or reducer.
entitiesT[] | Record<EntityId, T>Replacement entities, supplied as an array or as a record keyed by entity ID.

Returns

The updated entity state; when used as a case reducer, Redux Toolkit handles the resulting state update.

Key points

  • setAll is one of the reducer functions generated by createEntityAdapter.
  • Its collection argument can be either an entity array or an ID-keyed record.
  • The operation replaces the complete current entity collection rather than merging with it.
  • You can use setAll directly as a case reducer when its action payload matches the expected collection input.
  • You can also invoke setAll inside a case-reducer body alongside other draft updates.

Common mistakes

  • The second argument may be an array or an ID-keyed record; supplying another shape is unsupported.
  • setAll is destructive for the collection: entities missing from the incoming data are removed.

Example: Replace an entity collection

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

type Todo = { id: string; text: string }
const todosAdapter = createEntityAdapter<Todo>()

const todosSlice = createSlice({
  name: 'todos',
  initialState: todosAdapter.getInitialState(),
  reducers: {
    todosReceived(state, action: { payload: Todo[] }) {
      todosAdapter.setAll(state, action.payload)
    },
  },
})

export default todosSlice.reducer

The reducer replaces the adapter-managed collection with the payload array whenever todosReceived is dispatched.

When to use it

Load a complete server snapshot

A fetch operation returns the authoritative current collection; replace stale normalized data with the response.

Apply normalized API data

An already-normalized response contains an ID-keyed entities object; store it without converting it to an array.

Reset entity data

A slice needs to reset a collection after logout, tenant switching, or another full-context change.

Interview questions

QWhat does adapter.setAll do?

setAll is a generated entity-adapter reducer that replaces the entire normalized collection. It receives the current entity state and either an array of entities or an ID-keyed record.

Follow-up: How would you preserve existing entities while incorporating incoming data? Use addMany or upsertMany instead, depending on whether existing IDs should be left unchanged or updated.

QHow is setAll commonly used in Redux Toolkit?

Use it as a case reducer or as a mutating helper inside a createSlice or createReducer case. In a slice, call adapter.setAll(state, action.payload), where the payload contains the replacement collection.

Follow-up: Why is this safe despite the apparent mutation? Redux Toolkit case reducers use Immer drafts, so the helper can express updates through draft mutation while producing immutable state.

QWhat state representation does setAll update?

The adapter stores normalized data in an entity state with IDs and an entities lookup. setAll rebuilds that collection from the supplied values, applying the adapter's configured ID selection and sorting behavior.

Follow-up: What input is useful when an API response is already normalized? Pass the ID-keyed entities object directly, because setAll accepts that form without requiring an array conversion.

  • createEntityAdapter
  • getInitialState
  • addMany
  • upsertMany
  • removeMany
  • selectAll

Source: createEntityAdapter. Checked 2026-10-15.