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

Redux Toolkit · Module

adapter.addOne

adapter.addOne is a generated Redux Toolkit reducer for inserting one entity into normalized entity state. It adds the entity only when its ID is not already present and can be used directly as a case reducer or as an Immer helper.

How it works

addOne is a generated entity-adapter reducer that inserts one entity into normalized entity state only when its ID is not already present. It accepts either the state plus an entity directly or the state plus a Redux action whose payload is the entity, and it can be used directly as a case reducer or as an Immer-aware helper.

Syntax

addOne<S extends EntityState<T>>(state: S, entity: T): S
addOne<S extends EntityState<T>>(state: S, action: PayloadAction<T>): S

Parameters

NameTypeDescription
stateEntityState<T>The entity state managed by the adapter, containing normalized IDs and entities.
entity or actionT | PayloadAction<T>The entity to insert, or a Redux action whose payload contains that entity.

Returns

The updated entity state, with the entity added when its ID is not already present.

Key points

  • The direct TypeScript signature accepts entity state and one entity, returning the resulting state.
  • It also supports a Redux action form where the entity is carried in the action payload.
  • Only one entity is processed, and an already-present ID is not added again.
  • Use the adapter method directly as a reducer definition in either createReducer or createSlice.
  • Inside an Immer-backed reducer, call addOne as a helper when you need to combine it with other reducer logic.
  • addOne belongs to the adapter's generated CRUD reducers for normalized entity collections.

Common mistakes

  • Calling addOne for an ID that already exists does not replace the stored entity; use upsertOne when insertion or replacement is intended.
  • When calling addOne manually inside a reducer, pass the draft state supplied by createReducer or createSlice; standalone plain-state usage follows the returned-state form.

Example: Add one entity to a slice

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

type Todo = { id: string; text: string; done: boolean }

const todosAdapter = createEntityAdapter<Todo>()

const todosSlice = createSlice({
  name: 'todos',
  initialState: todosAdapter.getInitialState(),
  reducers: {
    todoAdded: todosAdapter.addOne,
  },
})

const state = todosSlice.reducer(undefined, {
  type: 'todos/todoAdded',
  payload: { id: '1', text: 'Read the docs', done: false },
})

console.log(state.entities['1'])

Creates an entity adapter and uses addOne as a slice case reducer to insert a Todo.

When to use it

Direct case reducer

Define a slice reducer that handles an add action without writing insertion logic.

Combined reducer logic

Add one record while performing additional logic in an Immer-backed reducer.

Normalized entity storage

Maintain a normalized collection keyed by entity IDs.

Interview questions

QWhat does adapter.addOne do?

addOne inserts one entity into an entity adapter's normalized state when that entity's ID is absent. It can be supplied directly as a case reducer to createSlice or createReducer.

Follow-up: How would you replace an existing entity as well as add missing ones? Use the adapter's upsertOne method instead.

QWhat are the supported call signatures?

The case-reducer form receives an action whose payload is the entity, matching the overload addOne(state, action). The direct helper form receives the entity as its second argument, matching addOne(state, entity).

Follow-up: What must a manually invoked helper receive inside a slice reducer? An Immer Draft state, so the adapter can apply its mutation-style update safely.

QWhat state shape does addOne update?

An entity adapter manages normalized entity state with an ids collection and an entities lookup. addOne updates that structure by adding the new ID and storing the entity when the ID is not already present.

Follow-up: Which adapter method replaces the whole collection? setAll replaces existing items with the supplied collection.

  • createEntityAdapter
  • EntityState
  • createSlice
  • createReducer
  • upsertOne
  • addMany
  • getInitialState
  • setAll

Source: createEntityAdapter. Checked 2026-10-15.