mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
fix: Search text result
This commit is contained in:
parent
d1ea2354ee
commit
90fbe59c7e
@ -1,6 +1,7 @@
|
|||||||
import { SWRHook } from '@commerce/utils/types'
|
import { SWRHook } from '@commerce/utils/types'
|
||||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||||
import data from '../data.json'
|
import data from '../data.json'
|
||||||
|
import useCallback from 'react'
|
||||||
export default useSearch as UseSearch<typeof handler>
|
export default useSearch as UseSearch<typeof handler>
|
||||||
|
|
||||||
const productsFinder = (s: string) => {
|
const productsFinder = (s: string) => {
|
||||||
@ -16,17 +17,21 @@ export const handler: SWRHook<any> = {
|
|||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
query: '',
|
query: '',
|
||||||
},
|
},
|
||||||
async fetcher({ input, options, fetch }) {},
|
async fetcher({ input, options, fetch }) {
|
||||||
|
debugger
|
||||||
|
},
|
||||||
useHook:
|
useHook:
|
||||||
({ useData }) =>
|
({ useData }) =>
|
||||||
({ search }) => {
|
({ search }) => {
|
||||||
const { mutate } = useData()
|
|
||||||
const products = productsFinder(search)
|
const products = productsFinder(search)
|
||||||
mutate()
|
|
||||||
return {
|
return {
|
||||||
data: {
|
data:
|
||||||
products,
|
products.length > 0
|
||||||
},
|
? {
|
||||||
|
products,
|
||||||
|
found: true,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user