useQuery
Endpoint and input — no cache key, no query function:
import { useQuery } from '@tahanabavi/typefetch-react'
function UserCard({ id }: { id: string }) {
const user = useQuery(
api.modules.user.getUser,
{ path: { id } },
{
staleTime: 30_000,
}
)
if (user.isLoading) return <p>loading…</p>
if (user.isError) return <p>{user.error?.message}</p>
return <p>{user.data?.name}</p> // data is inferred from the contract
}Changing input switches to that key's cache entry; a revisit is served from
cache until it goes stale.