setValueAtPath
constsetValueAtPath: <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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
obj | T |
path | string[] |
value | any |
Returns
Section titled “Returns”T