'use client' import { isServer, useSuspenseQuery } from '@tanstack/react-query' import { Suspense } from 'react' export const runtime = 'edge' // 'nodejs' (default) | 'edge' function getBaseURL() { if (!isServer) { return '' } if (process.env.VERCEL_URL) { return `https://${process.env.VERCEL_URL}` } return 'http://localhost:3000' } const baseUrl = getBaseURL() function useWaitQuery(props: { wait: number }) { const query = useSuspenseQuery({ queryKey: ['wait', props.wait], queryFn: async () => { const path = `/api/wait?wait=${props.wait}` const url = baseUrl + path const res: string = await ( await fetch(url, { cache: 'no-store', }) ).json() return res }, }) return [query.data as string, query] as const } function MyComponent(props: { wait: number }) { const [data] = useWaitQuery(props) return