updateData()function

updateData(data: T, updates: Updates<T>): T
ParamType
dataT
The data object to update. required
updatesUpdates<T>
The set of updates to apply. required
Return
T
The updated data object (or the original reference if nothing changed).
Throws
unknown
RequiredError if a +=/-= sum update has a non-number value.

Return a copy of a data object with a set of updates applied.

  • Returns the original reference unchanged when no update changed a value.
  • Supports nested paths, sum/increment, and array add/remove updates via the encoded Updates syntax.

Examples

updateData({ count: 1 }, { "+=count": 2 }) // { count: 3 }