forked from crowetic/commerce
bug fixes
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export function useSearchMeta(asPath: string) {
|
||||
const [pathname, setPathname] = useState<string>('/search')
|
||||
const [category, setCategory] = useState<string | undefined>()
|
||||
const [brand, setBrand] = useState<string | undefined>()
|
||||
|
||||
useEffect(() => {
|
||||
const parts = asPath.split('/')
|
||||
// Only access asPath after hydration to avoid a server mismatch
|
||||
const path = asPath.split('?')[0]
|
||||
const parts = path.split('/')
|
||||
|
||||
console.log('P', parts)
|
||||
|
||||
let c = parts[2]
|
||||
let b = parts[3]
|
||||
@@ -14,11 +19,12 @@ export function useSearchMeta(asPath: string) {
|
||||
c = parts[4]
|
||||
}
|
||||
|
||||
setPathname(path)
|
||||
if (c !== category) setCategory(c)
|
||||
if (b !== brand) setBrand(b)
|
||||
}, [asPath])
|
||||
|
||||
return { category, brand }
|
||||
return { pathname, category, brand }
|
||||
}
|
||||
|
||||
// Removes empty query parameters from the query object
|
||||
|
Reference in New Issue
Block a user