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

Redux Toolkit · Module

adapter.removeMany

removeMany is a generated entity-adapter reducer that removes all entities matching a supplied array of IDs. Use it directly as a slice/reducer case or call it as an Immer helper inside reducer logic.

How it works

removeMany updates an entity adapter's normalized state by deleting each entity identified by the supplied ID array. It can be used directly as a case reducer or called as an Immer-backed mutating helper inside a reducer.

Syntax

removeMany(state, keys: EntityId[]): EntityState<T>
removeMany(state, action: PayloadAction<EntityId[]>): EntityState<T>

Parameters

NameTypeDescription
stateEntityState<T>The adapter-managed normalized entity state, or an Immer Draft of it when called manually.
keysEntityId[] | PayloadAction<EntityId[]>The IDs of entities to remove; this is a plain array for helper use or a PayloadAction containing that array as payload for case-reducer use.

Returns

The updated entity state, with matching entities removed.

Key points

  • The input is an array of entity IDs, and every matching entity is deleted.
  • As a manual helper, the method takes entity state plus a plain ID array and returns the state type.
  • As a case reducer, the second argument is an action whose payload is an array of entity IDs.
  • The adapter method can be registered directly in either createReducer or createSlice.
  • It can also be called from handwritten reducer logic as an Immer-style mutating helper.
  • The method belongs to the adapter's generated CRUD operations for normalized entity state.

Common mistakes

  • IDs that are absent from the state are ignored; only matching entities are removed.
  • When called manually as a helper, pass an Immer Draft state rather than an ordinary immutable state value.

Example: Remove several entities from an adapter state

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: {
    removeSelected: (state, action: { payload: string[] }) => {
      todosAdapter.removeMany(state, action.payload)
    },
  },
})

export const { removeSelected } = todosSlice.actions
export default todosSlice.reducer

Removes every entity whose ID appears in the action payload.

When to use it

Bulk deletion from a slice

A slice receives an action containing several IDs that should be deleted.

Handwritten reducer cleanup

Reducer logic already has a list of IDs and needs to remove them in one adapter operation.

Maintaining normalized entity state

A normalized collection must remove selected records while keeping its adapter-managed state consistent.

Interview questions

QWhat does removeMany do?

removeMany is a generated entity-adapter reducer that accepts an array of entity IDs and removes matching entities from normalized state. It can be supplied directly as a case reducer or invoked inside another reducer.

Follow-up: How would you invoke it inside a slice reducer? Call adapter.removeMany(state, ids) where state is the reducer's Immer Draft and ids is the ID array.

QWhat are the supported call signatures?

The case-reducer form receives an action whose payload contains the IDs to delete, with the signature removeMany(state, keys: PayloadAction<EntityId[]>). The direct-helper form instead receives the ID array as its second argument.

Follow-up: What changes between the two forms? Only the input shape: an action payload for case-reducer use versus a plain ID array for a manual helper call.

QWhat happens when some supplied IDs are missing?

It operates on an entity adapter's normalized entity state and checks each supplied ID. Existing matching entities are removed, while nonexistent IDs have no effect.

Follow-up: Why is normalized state useful here? The adapter maintains the generated ids and entities structures together, so callers do not manually coordinate both collections.

  • createEntityAdapter
  • EntityState
  • EntityId
  • createReducer
  • createSlice
  • removeOne
  • addMany
  • upsertMany

Source: createEntityAdapter. Checked 2026-10-15.