fix: Search text result

This commit is contained in:
Alessandro Casazza 2021-10-13 11:59:54 +02:00
parent d1ea2354ee
commit 90fbe59c7e
No known key found for this signature in database
GPG Key ID: 3AF41B06C6495D3D

View File

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