Skip to content

Commit

Permalink
fix(filter): replace router for lagging filter
Browse files Browse the repository at this point in the history
  • Loading branch information
purusott committed Jul 3, 2024
1 parent 8a45bf0 commit 1a53b28
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions next-tavla/app/(admin)/boards/hooks/useSearchParamReplacer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { usePathname, useSearchParams, useRouter } from 'next/navigation'
import { usePathname, useSearchParams } from 'next/navigation'
import { useCallback } from 'react'
import { useSearchParam } from './useSearchParam'

function useSearchParamReplacer(
param: string,
): [string | undefined, (value?: string) => void] {
const router = useRouter()
const pathname = usePathname()
const params = useSearchParams()
const value = useSearchParam(param)
Expand All @@ -15,12 +14,13 @@ function useSearchParamReplacer(
const newParams = new URLSearchParams(params ?? undefined)
if (!value || value === '') newParams.delete(param)
else newParams.set(param, value)

router.replace(
window.history.replaceState(
{},
'',
`${pathname}?${newParams.toString().replace(/%2C/g, ',')}`,
)
},
[router, pathname, param, params],
[pathname, param, params],
)
return [value, replace]
}
Expand Down

0 comments on commit 1a53b28

Please sign in to comment.