forked from crowetic/commerce
Updated types for swr hooks
This commit is contained in:
parent
dca8f281ab
commit
7633a6fae8
@ -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],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user