Skip to content

Commit

Permalink
feat: add support for compare states with bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio committed Feb 19, 2024
1 parent f32be82 commit cb080c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thirty-hairs-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuels/react-xstore': patch
---

feat: add stringify support for bigint
9 changes: 8 additions & 1 deletion packages/react-xstore/src/utils/deepCompare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
*/
export function deepCompare(a: unknown, b: unknown) {
if (typeof a === 'object') {
return JSON.stringify(a) === JSON.stringify(b);
return JSON.stringify(a, stringifyBigInts) === JSON.stringify(b, stringifyBigInts);
}
return a === b;
}

export function stringifyBigInts(key: string, value: unknown) {
if (typeof value === 'bigint') {
return value.toString();
}
return value;
}

0 comments on commit cb080c9

Please sign in to comment.