Skip to content

Commit 47a7abd

Browse files
FL4TLiN3claude
andcommitted
feat(react): add useEventStream hook for consuming PerstackEvent streams
Add a new useEventStream hook that provides automatic connection management for PerstackEvent streams. The hook is API-agnostic and accepts an EventSourceFactory function, allowing it to work with any backend. Features: - Automatic connection lifecycle management - Event processing through useRun hook internally - Connection state tracking (isConnected, error) - Proper cleanup on unmount or when disabled - AbortSignal support for stream cancellation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f8eff15 commit 47a7abd

File tree

5 files changed

+541
-0
lines changed

5 files changed

+541
-0
lines changed

.changeset/add-use-event-stream.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@perstack/react": patch
3+
---
4+
5+
feat(react): add useEventStream hook for consuming PerstackEvent streams
6+
7+
Added a new `useEventStream` hook that provides automatic connection management for PerstackEvent streams. The hook is API-agnostic and accepts an `EventSourceFactory` function, allowing it to work with any backend that provides PerstackEvent streams.
8+
9+
Features:
10+
- Automatic connection lifecycle management (connect/disconnect based on `enabled` flag)
11+
- Event processing through `useRun` hook internally
12+
- Connection state tracking (`isConnected`, `error`)
13+
- Proper cleanup on unmount or when disabled
14+
- AbortSignal support for stream cancellation

packages/react/src/hooks/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
export {
2+
type EventSourceFactory,
3+
type EventStreamOptions,
4+
type EventStreamState,
5+
type UseEventStreamOptions,
6+
useEventStream,
7+
} from "./use-event-stream.js"
18
export { type ActivityProcessState, type RunResult, useRun } from "./use-run.js"
29
export { type RuntimeResult, useRuntime } from "./use-runtime.js"

0 commit comments

Comments
 (0)