Skip to content

Commit

Permalink
oppgraderer zustand -> ^5.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
urenhale committed Jan 17, 2025
1 parent a7de26f commit 7182336
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
23 changes: 13 additions & 10 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/compare-alternatives-state-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const useAlternativeProductCompareStore = create<AlternativeProductCompar
// 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 useHydratedAlternativeProductsCompareStore = ((selector, compare) => {
const store = useAlternativeProductCompareStore(selector, compare)
export const useHydratedAlternativeProductsCompareStore = (() => {
const store = useAlternativeProductCompareStore()
const [hydrated, setHydrated] = useState(false)
useEffect(() => setHydrated(true), [])
return hydrated
Expand Down
24 changes: 12 additions & 12 deletions src/utils/global-state-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -26,7 +26,7 @@ export const useProductCompareStore = create<ProductCompareState>()(
compareMenuState: CompareMenuState.Minimized,
productsToCompare: [],
setCompareMenuState: (menuState) => set(() => ({ compareMenuState: menuState })),
setProductToCompare: (product) =>{
setProductToCompare: (product) => {
set((state) => ({ productsToCompare: state.productsToCompare.concat(product) }))
},
removeProduct: (productId: string) =>
Expand All @@ -46,20 +46,20 @@ export const useProductCompareStore = create<ProductCompareState>()(
// 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 = {
Expand Down

0 comments on commit 7182336

Please sign in to comment.