categories,18popup,clear.TextEditorSwap,GameCardHover #177

Merged
freakoverse merged 64 commits from staging into master 2024-12-24 19:44:30 +00:00
2 changed files with 18 additions and 6 deletions
Showing only changes of commit cbcb82e779 - Show all commits

View File

@ -1,4 +1,4 @@
import React from 'react'
import React, { useMemo } from 'react'
import {
getLocalStorageItem,
removeLocalStorageItem,
@ -11,7 +11,11 @@ const useLocalStorageSubscribe = (callback: () => void) => {
}
function mergeWithInitialValue<T>(storedValue: T, initialValue: T): T {
if (typeof storedValue === 'object' && storedValue !== null) {
if (
!Array.isArray(storedValue) &&
typeof storedValue === 'object' &&
storedValue !== null
) {
return { ...initialValue, ...storedValue }
}
return storedValue
@ -64,5 +68,7 @@ export function useLocalStorage<T>(
}
}, [key, initialValue])
return [JSON.parse(data) as T, setState]
const memoized = useMemo(() => JSON.parse(data) as T, [data])
return [memoized, setState]
}

View File

@ -1,4 +1,4 @@
import React from 'react'
import React, { useMemo } from 'react'
import {
getSessionStorageItem,
removeSessionStorageItem,
@ -11,7 +11,11 @@ const useSessionStorageSubscribe = (callback: () => void) => {
}
function mergeWithInitialValue<T>(storedValue: T, initialValue: T): T {
if (typeof storedValue === 'object' && storedValue !== null) {
if (
!Array.isArray(storedValue) &&
typeof storedValue === 'object' &&
storedValue !== null
) {
return { ...initialValue, ...storedValue }
}
return storedValue
@ -67,5 +71,7 @@ export function useSessionStorage<T>(
}
}, [key, initialValue])
return [JSON.parse(data) as T, setState]
const memoized = useMemo(() => JSON.parse(data) as T, [data])
return [memoized, setState]
}