fix: unnecessory data fetch when swithing apps category on explore page (#5155)

This commit is contained in:
doufa
2024-06-19 09:33:19 +00:00
committed by GitHub
parent c923684edd
commit e05183c7d2

View File

@@ -1,4 +1,4 @@
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { usePathname, useSearchParams } from 'next/navigation'
import { useState } from 'react'
type UseTabSearchParamsOptions = {
@@ -24,7 +24,6 @@ export const useTabSearchParams = ({
searchParamName = 'category',
disableSearchParams = false,
}: UseTabSearchParamsOptions) => {
const router = useRouter()
const pathName = usePathname()
const searchParams = useSearchParams()
const [activeTab, setTab] = useState<string>(
@@ -37,7 +36,7 @@ export const useTabSearchParams = ({
setTab(newActiveTab)
if (disableSearchParams)
return
router[routingBehavior](`${pathName}?${searchParamName}=${newActiveTab}`)
history[`${routingBehavior}State`](null, '', `${pathName}?${searchParamName}=${newActiveTab}`)
}
return [activeTab, setActiveTab] as const