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

Redux Toolkit · Module

adapter.updateMany

adapter.updateMany applies partial, shallow updates to multiple entities in a normalized entity state. Each update targets an ID and supplies changed fields through changes.

How it works

Call the adapter method with entity state and an array of update objects. Each object names an entity through id and supplies partial fields in changes; matching entities are shallowly updated, while repeated IDs are consolidated with later values taking precedence.

Syntax

updateMany<S extends EntityState<T>>(state: S, updates: Update<T>[]): S

Parameters

NameTypeDescription
stateEntityState<T>The normalized entity state to modify.
updatesUpdate<T>[]An array of update objects; each identifies an entity and supplies partial fields in changes.

Returns

The updated entity state, preserving the state type.

Key points

  • It updates every entity referenced by the supplied update-object array.
  • The direct utility signature takes entity state followed by an array of typed updates and returns the resulting state.
  • As a case reducer, it also accepts a payload action whose payload is the updates array.
  • Each update pairs an entity ID with partial field values under changes.
  • Multiple updates for one record are consolidated before application.
  • An ID collision caused by an update replaces the entity already stored under that destination ID.

Common mistakes

  • Updates are shallow merges: changing a nested object replaces that entire nested object, so these helpers work best with flat entities.
  • Repeated updates for one ID are combined, and later updates overwrite earlier fields.
  • Changing an entity's ID to another existing ID causes the first entity to replace the second completely.

Example: Update multiple entities

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

type User = { id: string; name: string; role: string }

const usersAdapter = createEntityAdapter<User>()
const usersSlice = createSlice({
  name: 'users',
  initialState: usersAdapter.getInitialState(),
  reducers: {
    usersUpdated: usersAdapter.updateMany,
  },
})

usersSlice.reducer(usersSlice.getInitialState(), {
  type: 'users/usersUpdated',
  payload: [
    { id: '1', changes: { role: 'admin' } },
    { id: '2', changes: { name: 'Ada Lovelace' } },
  ],
})

Registers updateMany as a slice reducer; dispatching an array of update objects applies shallow changes to every matching entity.

When to use it

Batch server synchronization

Several records from one API response need partial field changes.

Multi-entity action handling

A slice reducer receives one action containing changes for multiple entities.

Efficient normalized updates

Normalized records need targeted edits without rebuilding the collection.

Interview questions

QWhat does adapter.updateMany do?

It accepts the entity state and an array of Update objects, returning the updated state. Each update identifies an entity by id and provides partial fields in changes, which are applied shallowly.

Follow-up: What happens when two updates target the same ID? They are merged into one update, with later updates overwriting earlier values.

QHow can updateMany be integrated into a reducer?

It can be used as a case reducer in createReducer or createSlice, or as a mutating helper within another reducer. When used as a slice reducer, the action payload contains the updates array.

Follow-up: Why is the helper suitable for normalized state? The adapter operates on the generated ids/entities structure and targets records by ID.

QHow are updateMany changes applied?

The changes object is merged shallowly into each matching entity. A nested object supplied in changes replaces the existing nested object instead of being recursively merged.

Follow-up: What design follows from this behavior? Keep entity records relatively flat or construct complete replacement values for nested fields.

  • createEntityAdapter
  • EntityState
  • Update
  • updateOne
  • upsertMany
  • createSlice

Source: createEntityAdapter. Checked 2026-10-15.