From 03bd913d45e2c57594030c0a066afbae772936df Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Wed, 15 May 2024 13:01:47 +0200 Subject: [PATCH] fix(useSearchParamToggle): fixed issue where all search params where removed when changing setting --- src/components/auth/modals/hooks.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/auth/modals/hooks.ts b/src/components/auth/modals/hooks.ts index f86ca3a..c961146 100644 --- a/src/components/auth/modals/hooks.ts +++ b/src/components/auth/modals/hooks.ts @@ -5,11 +5,21 @@ export const useSearchParamToggle = (key: string) => { const value = searchParams.get(key) === "true" - const open = () => setSearchParams(prev => ({...prev, [key]: "true"}), {replace: true}) - const close = () => setSearchParams(prev => { - prev.delete(key) - return prev - }, {replace: true}) + const open = () => { + setSearchParams(prev => { + const newParams = new URLSearchParams(prev); + newParams.set(key, "true") + return newParams + }, { replace: true }) + } + + const close = () => { + setSearchParams(prev => { + const newParams = new URLSearchParams(prev); + newParams.delete(key); + return newParams; + }, { replace: true }) + } return { value: value,