diff --git a/package-lock.json b/package-lock.json index c1c3bc7f3..444ea0d0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,6 +55,7 @@ "react-router-dom": "^6.22.0", "remark-gfm": "^4.0.0", "sonner": "^1.5.0", + "use-between": "^1.3.5", "viem": "^2.13.1", "vite": "^5.3.4", "vite-plugin-checker": "^0.6.4", @@ -46019,6 +46020,15 @@ "node": ">=0.10.0" } }, + "node_modules/use-between": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/use-between/-/use-between-1.3.5.tgz", + "integrity": "sha512-IP9eJfszZr0aah/6i/pzaM7n/QgMPwWKJ+mnWqT5O0qFhLnztPbkVC6L7zI6ygeBIMJHfmUGvsw0b28pyrEGSA==", + "license": "MIT", + "peerDependencies": { + "react": ">=16.8.0" + } + }, "node_modules/use-callback-ref": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.0.tgz", diff --git a/package.json b/package.json index 4fb92ce4e..6e0e0c29b 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "react-router-dom": "^6.22.0", "remark-gfm": "^4.0.0", "sonner": "^1.5.0", + "use-between": "^1.3.5", "viem": "^2.13.1", "vite": "^5.3.4", "vite-plugin-checker": "^0.6.4", diff --git a/src/hooks/DAO/loaders/useFavorites.ts b/src/hooks/DAO/loaders/useFavorites.ts index 0b688608d..2aabcbe5c 100644 --- a/src/hooks/DAO/loaders/useFavorites.ts +++ b/src/hooks/DAO/loaders/useFavorites.ts @@ -1,13 +1,22 @@ import { useState } from 'react'; +import { useBetween } from 'use-between'; import { Address } from 'viem'; import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider'; import { CacheKeys, CacheExpiry, FavoritesCacheValue } from '../../utils/cache/cacheDefaults'; import { getValue, setValue } from '../../utils/cache/useLocalStorage'; -export const useAccountFavorites = () => { +const useSharedAccountFavorites = () => { const [favoritesList, setFavoritesList] = useState( getValue({ cacheName: CacheKeys.FAVORITES }) || [], ); + return { + favoritesList, + setFavoritesList + }; +}; + +export const useAccountFavorites = () => { + const { favoritesList, setFavoritesList } = useBetween(useSharedAccountFavorites) const { addressPrefix } = useNetworkConfig(); const toggleFavorite = (address: Address, name: string) => {