Skip to content

setValueAtPath

const setValueAtPath: <T>(obj, path, value) => T = _setValueAtPath

Defined in: index.ts:108

Set a value at a nested path in an object (immutably). Preserves array-ness of intermediate nodes — setValueAtPath(state, ['items', '0', 'qty'], 2) keeps items as an array, not an object with key “0”.

Writing the value already there (Object.is, key present) returns obj itself. Cloning the path anyway would hand every ancestor a new reference, so object selectors (s => s.user) would re-render for a write that changed nothing; adapters skip the commit when the reference is unchanged.

Type Parameter
T
ParameterType
objT
pathstring[]
valueany

T