Minimal React hooks for @gantryland/task
npm install @gantryland/task-reactMinimal React hooks for @gantryland/task.
Use this package for direct Task to React interop with no policy layer.
``bash`
npm install @gantryland/task-react @gantryland/task react
`typescript
import { Task } from "@gantryland/task";
import { useTask } from "@gantryland/task-react";
const userTask = new Task(async (signal, id: string) =>
fetch(/api/users/${id}, { signal }).then((r) => r.json()),
);
export function UserPanel({ id }: { id: string }) {
const { data, error, isLoading, run } = useTask(userTask);
return ( Loading... {error.message}
{isLoading &&
{error &&
{data && {JSON.stringify(data, null, 2)}}
);
}
`
- useTaskState(task) -> TaskStateuseTask(task)
- -> TaskState
- Subscriptions use useSyncExternalStore for React 18+ correctness.run
- Hooks do not add retries, caching, or scheduling policy.
- , cancel, and reset proxy directly to the Task instance.
- @gantryland/task - Task execution and state primitive
- @gantryland/task-combinators - TaskFn composition and control-flow operators
- @gantryland/task-cache - Cache combinators and in-memory store
`bash``
npx vitest packages/task-react/test