fix(useSearchParamToggle): fixed issue where all search params where removed when changing setting
Build and Push Docker image / build-and-push (push) Successful in 1m49s Details

This commit is contained in:
Valentin Kolb 2024-05-15 13:01:47 +02:00
parent cf82f4f957
commit 03bd913d45
1 changed files with 15 additions and 5 deletions

View File

@ -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,