A Resource, ResourceRelation, or URI string
Loading state, error, and resource data
import { useResource, useClient } from '@hateoas-ts/resource-react';
import type { User } from './types';
function UserProfile({ userId }: { userId: string }) {
const client = useClient();
const userResource = client.go<User>(`/api/users/${userId}`);
const { loading, error, data, resourceState } = useResource(userResource);
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
return <div>Welcome, {data.name}!</div>;
}
Hook for fetching and managing a single HATEOAS resource.
Automatically fetches the resource on mount and returns loading/error states along with the resource data. Use this hook when you need to display a single entity (not a collection).