Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
],
"author": "LovesWorking (https://github.com/LovesWorking)",
"license": "MIT",
"dependencies": {},
"dependencies": {
"fast-deep-equal": "^3.1.3"
},
"peerDependencies": {
"@tanstack/react-query": "^4.0.0 || ^5.0.0",
"react": "^18 || ^19",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useState } from 'react';
import { QueryClient, useQueries } from '@tanstack/react-query';

import isEqual from 'fast-deep-equal';
import { storageQueryKeys } from './storageQueryKeys';

/**
Expand Down Expand Up @@ -171,7 +171,7 @@ export function useDynamicAsyncStorageQueries({
// Only compare if we have cached data (avoid false positives after cache clear)
if (cachedData !== undefined) {
// Compare values (deep comparison for objects)
const valuesAreDifferent = JSON.stringify(currentValue) !== JSON.stringify(cachedData);
const valuesAreDifferent = !isEqual(currentValue, cachedData);

if (valuesAreDifferent) {
console.log('🔄 [AsyncStorage Hook] Value changed for key:', key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { QueryClient, useQueries } from '@tanstack/react-query';

import { storageQueryKeys } from './storageQueryKeys';
import isEqual from "fast-deep-equal";

/**
* SecureStore interface that matches expo-secure-store API
Expand Down Expand Up @@ -247,7 +248,7 @@ export function useDynamicSecureStorageQueries({
// Only compare if we have cached data (avoid false positives after cache clear)
if (cachedData !== undefined) {
// Deep comparison using a more robust method
const valuesAreDifferent = !deepEqual(currentValue, cachedData);
const valuesAreDifferent = !isEqual(currentValue, cachedData);

if (valuesAreDifferent) {
console.log('🔄 [SecureStore Hook] Value changed for key:', key);
Expand Down Expand Up @@ -308,24 +309,4 @@ export function useDynamicSecureStorageQueries({
}

return queries;
}

// Helper function for deep equality comparison
function deepEqual(a: unknown, b: unknown): boolean {
if (a === b) return true;

if (a === null || b === null || a === undefined || b === undefined) {
return a === b;
}

if (typeof a !== typeof b) return false;

if (typeof a !== 'object') return a === b;

// For objects, use JSON comparison as fallback but handle edge cases
try {
return JSON.stringify(a) === JSON.stringify(b);
} catch {
return false;
}
}
}