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 value = searchParams.get(key) === "true"
const open = () => setSearchParams(prev => ({...prev, [key]: "true"}), {replace: true}) const open = () => {
const close = () => setSearchParams(prev => { setSearchParams(prev => {
prev.delete(key) const newParams = new URLSearchParams(prev);
return prev newParams.set(key, "true")
}, {replace: true}) return newParams
}, { replace: true })
}
const close = () => {
setSearchParams(prev => {
const newParams = new URLSearchParams(prev);
newParams.delete(key);
return newParams;
}, { replace: true })
}
return { return {
value: value, value: value,