Skip to content
TypeWire

@tahanabavi/typefetch-react

v1.1.0

React adapter for the TypeFetch query engine — useQuery, useMutation, TypeFetchProvider.

useQuery

Endpoint and input — no cache key, no query function:

tsx
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.