dynamic-forms / Function

getChangedKeys

Gets the keys that differ between two objects.

Compares top-level keys and returns those whose values are different. Uses deep equality comparison for nested values.

Presentation

function getChangedKeys(
  previous: Record<string, unknown> | null | undefined,
  current: Record<string, unknown> | null | undefined,
): Set<string>;

Returns

Set<string> -

Set of keys that have different values

Parameters

NameTypeDescription
previous
Record<string, unknown> | null | undefined

Previous object state

current
Record<string, unknown> | null | undefined

Current object state

Example usage

const prev = { a: 1, b: 2, c: 3 };
const curr = { a: 1, b: 5, d: 4 };
getChangedKeys(prev, curr); // Set { 'b', 'c', 'd' }