4
0
forked from crowetic/commerce

bug fixes

This commit is contained in:
Luis Alvarez
2020-10-14 13:12:34 -05:00
parent 32da7ddcc1
commit 8905089fd7
3 changed files with 10 additions and 5 deletions

View File

@@ -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