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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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