use-s-react
Version:
useS is a minimal yet powerful React hook for managing both local and global state — with zero boilerplate
19 lines (18 loc) • 562 B
JavaScript
export function deepAssign(target, source) {
for (const key in source) {
const sourceValue = source[key];
const targetValue = target[key];
if (typeof sourceValue === "object" &&
sourceValue !== null &&
!Array.isArray(sourceValue) &&
typeof targetValue === "object" &&
targetValue !== null &&
!Array.isArray(targetValue)) {
deepAssign(targetValue, sourceValue);
}
else {
target[key] = sourceValue;
}
}
return target;
}