'use client'
import {
type QueryKey,
type UseSuspenseQueryOptions,
type UseSuspenseQueryResult,
useSuspenseQuery,
} from '@tanstack/react-query'
import type { ReactNode } from 'react'
/**
* We provide these components to clearly express what causes suspense at the same depth.
* `` serves to make `useSuspenseQuery` easier to use in jsx.
* @see {@link https://suspensive.org/docs/react-query/SuspenseQuery Suspensive Docs}
* @example
* ```tsx
* import { SuspenseQuery } from '@suspensive/react-query'
*
* // You can use QueryOptions as props.
*
* {({ data, isLoading }) => {
* return <>>
* }
*
* ```
*/
export const SuspenseQuery = <
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
>({
children,
...options
}: UseSuspenseQueryOptions & {
children: (queryResult: UseSuspenseQueryResult) => ReactNode
}) => <>{children(useSuspenseQuery(options))}>