Skip to content

Commit

Permalink
perf: improve conditional check for array of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mayan-000 committed Feb 15, 2024
1 parent c6874ed commit aa5167e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/common/src/utils/shallowEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export const shallowEqual = (a: unknown, b: unknown): boolean => {
}

if (Array.isArray(a) && Array.isArray(b)) {
if (
typeof a[0] === 'object' &&
typeof b[0] === 'object' &&
a.length === b.length
) {
return a.every((item, index) => shallowEqualObjects(item, b[index]));
}

return shallowEqualArrays(a, b);
}

Expand Down

0 comments on commit aa5167e

Please sign in to comment.