mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
21 lines
676 B
TypeScript
21 lines
676 B
TypeScript
import { useHook, useSWRHook } from '../utils/use-hook'
|
|
import { SWRFetcher } from '../utils/default-fetcher'
|
|
import type { HookFetcherFn, SWRHook } from '../utils/types'
|
|
import type { SearchProductsHook } from '../types/product'
|
|
import type { Provider } from '..'
|
|
|
|
export type UseSearch<
|
|
H extends SWRHook<SearchProductsHook<any>> = SWRHook<SearchProductsHook>
|
|
> = ReturnType<H['useHook']>
|
|
|
|
export const fetcher: HookFetcherFn<SearchProductsHook> = SWRFetcher
|
|
|
|
const fn = (provider: Provider) => provider.products?.useSearch!
|
|
|
|
const useSearch: UseSearch = (input) => {
|
|
const hook = useHook(fn)
|
|
return useSWRHook({ fetcher, ...hook })(input)
|
|
}
|
|
|
|
export default useSearch
|