forked from crowetic/commerce
Merge branch 'master' of github.com:okbel/e-comm-example
This commit is contained in:
commit
81f4771c4d
@ -1,5 +1,5 @@
|
|||||||
import { ConfigInterface } from 'swr'
|
import type { HookFetcher } from '@lib/commerce/utils/types'
|
||||||
import { HookFetcher } from '@lib/commerce/utils/types'
|
import type { SwrOptions } from '@lib/commerce/utils/use-data'
|
||||||
import useCommerceCart, { CartInput } from '@lib/commerce/cart/use-cart'
|
import useCommerceCart, { CartInput } from '@lib/commerce/cart/use-cart'
|
||||||
import type { Cart } from '../api/cart'
|
import type { Cart } from '../api/cart'
|
||||||
|
|
||||||
@ -20,10 +20,10 @@ export const fetcher: HookFetcher<Cart | null, CartInput> = (
|
|||||||
|
|
||||||
export function extendHook(
|
export function extendHook(
|
||||||
customFetcher: typeof fetcher,
|
customFetcher: typeof fetcher,
|
||||||
swrOptions?: ConfigInterface
|
swrOptions?: SwrOptions<Cart | null, CartInput>
|
||||||
) {
|
) {
|
||||||
const useCart = () => {
|
const useCart = () => {
|
||||||
const cart = useCommerceCart<Cart | null>(defaultOpts, [], customFetcher, {
|
const cart = useCommerceCart(defaultOpts, [], customFetcher, {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
...swrOptions,
|
...swrOptions,
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ConfigInterface } from 'swr'
|
import type { HookFetcher } from '@lib/commerce/utils/types'
|
||||||
import { HookFetcher } from '@lib/commerce/utils/types'
|
import type { SwrOptions } from '@lib/commerce/utils/use-data'
|
||||||
import useCommerceSearch from '@lib/commerce/products/use-search'
|
import useCommerceSearch from '@lib/commerce/products/use-search'
|
||||||
import type { SearchProductsData } from '../api/catalog/products'
|
import type { SearchProductsData } from '../api/catalog/products'
|
||||||
|
|
||||||
@ -38,10 +38,10 @@ export const fetcher: HookFetcher<SearchProductsData, SearchProductsInput> = (
|
|||||||
|
|
||||||
export function extendHook(
|
export function extendHook(
|
||||||
customFetcher: typeof fetcher,
|
customFetcher: typeof fetcher,
|
||||||
swrOptions?: ConfigInterface
|
swrOptions?: SwrOptions<SearchProductsData, SearchProductsInput>
|
||||||
) {
|
) {
|
||||||
const useSearch = (input: SearchProductsInput = {}) => {
|
const useSearch = (input: SearchProductsInput = {}) => {
|
||||||
const response = useCommerceSearch<SearchProductsData>(
|
const response = useCommerceSearch(
|
||||||
defaultOpts,
|
defaultOpts,
|
||||||
[
|
[
|
||||||
['search', input.search],
|
['search', input.search],
|
||||||
@ -49,7 +49,7 @@ export function extendHook(
|
|||||||
['brandId', input.brandId],
|
['brandId', input.brandId],
|
||||||
['sort', input.sort],
|
['sort', input.sort],
|
||||||
],
|
],
|
||||||
customFetcher as any,
|
customFetcher,
|
||||||
{ revalidateOnFocus: false, ...swrOptions }
|
{ revalidateOnFocus: false, ...swrOptions }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user