diff --git a/package-lock.json b/package-lock.json index a294c472..aa012c03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,7 @@ "react-snowfall": "^2.2.0", "swr": "^2.3.0", "zod": "^3.24.1", - "zustand": "^4.5.5" + "zustand": "^5.0.3" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", @@ -5999,6 +5999,8 @@ "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz", "integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==", "license": "MIT", + "optional": true, + "peer": true, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0" } @@ -6146,20 +6148,18 @@ "license": "MIT" }, "node_modules/zustand": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.5.tgz", - "integrity": "sha512-+0PALYNJNgK6hldkgDq2vLrw5f6g/jCInz52n9RTpropGgeAf/ioFUCdtsjCqu4gNhW9D01rUQBROoRjdzyn2Q==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.3.tgz", + "integrity": "sha512-14fwWQtU3pH4dE0dOpdMiWjddcH+QzKIgk1cl8epwSE7yag43k/AD/m4L6+K7DytAOr9gGBe3/EXj9g7cdostg==", "license": "MIT", - "dependencies": { - "use-sync-external-store": "1.2.2" - }, "engines": { - "node": ">=12.7.0" + "node": ">=12.20.0" }, "peerDependencies": { - "@types/react": ">=16.8", + "@types/react": ">=18.0.0", "immer": ">=9.0.6", - "react": ">=16.8" + "react": ">=18.0.0", + "use-sync-external-store": ">=1.2.0" }, "peerDependenciesMeta": { "@types/react": { @@ -6170,6 +6170,9 @@ }, "react": { "optional": true + }, + "use-sync-external-store": { + "optional": true } } } diff --git a/package.json b/package.json index def9d0bf..560553cf 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "react-snowfall": "^2.2.0", "swr": "^2.3.0", "zod": "^3.24.1", - "zustand": "^4.5.5" + "zustand": "^5.0.3" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", diff --git a/src/utils/compare-alternatives-state-util.ts b/src/utils/compare-alternatives-state-util.ts index 00623446..5c257aa3 100644 --- a/src/utils/compare-alternatives-state-util.ts +++ b/src/utils/compare-alternatives-state-util.ts @@ -49,8 +49,8 @@ export const useAlternativeProductCompareStore = create { - const store = useAlternativeProductCompareStore(selector, compare) +export const useHydratedAlternativeProductsCompareStore = (() => { + const store = useAlternativeProductCompareStore() const [hydrated, setHydrated] = useState(false) useEffect(() => setHydrated(true), []) return hydrated diff --git a/src/utils/global-state-util.ts b/src/utils/global-state-util.ts index 21a11e5b..758eac7d 100644 --- a/src/utils/global-state-util.ts +++ b/src/utils/global-state-util.ts @@ -4,7 +4,7 @@ import { useEffect, useState } from 'react' import { create } from 'zustand' import { createJSONStorage, persist } from 'zustand/middleware' -import { Product } from "@/utils/product-util"; +import { Product } from '@/utils/product-util' export enum CompareMenuState { Open = 'Open', @@ -14,7 +14,7 @@ export enum CompareMenuState { type ProductCompareState = { compareMenuState: CompareMenuState setCompareMenuState: (state: CompareMenuState) => void - productsToCompare: (Product)[] + productsToCompare: Product[] setProductToCompare: (product: Product) => void removeProduct: (productId: string) => void resetProductToCompare: () => void @@ -26,7 +26,7 @@ export const useProductCompareStore = create()( compareMenuState: CompareMenuState.Minimized, productsToCompare: [], setCompareMenuState: (menuState) => set(() => ({ compareMenuState: menuState })), - setProductToCompare: (product) =>{ + setProductToCompare: (product) => { set((state) => ({ productsToCompare: state.productsToCompare.concat(product) })) }, removeProduct: (productId: string) => @@ -46,20 +46,20 @@ export const useProductCompareStore = create()( // otherwise it causes a mismatch between SSR and client render // see: https://github.com/pmndrs/zustand/issues/1145 // https://github.com/TxnLab/use-wallet/pull/23/commits/f4c13aad62839500066d694a5b0f4a4c24c3c8d3 -export const useHydratedCompareStore = ((selector, compare) => { - const store = useProductCompareStore(selector, compare) +export const useHydratedCompareStore = (() => { + const store = useProductCompareStore() const [hydrated, setHydrated] = useState(false) useEffect(() => setHydrated(true), []) return hydrated ? store : { - compareMenuState: CompareMenuState.Minimized, - productsToCompare: [], - setCompareMenuState: () => undefined, - setProductToCompare: () => undefined, - removeProduct: () => undefined, - resetProductToCompare: () => undefined, - } + compareMenuState: CompareMenuState.Minimized, + productsToCompare: [], + setCompareMenuState: () => undefined, + setProductToCompare: () => undefined, + removeProduct: () => undefined, + resetProductToCompare: () => undefined, + } }) as typeof useProductCompareStore type MenuState = {