[]previous and next page

useSSE

Subscribes to a server-sent events route from a component: data holds the last event's data and status the connection's state.

Subscribes to a server-sent events route from a component: data holds the last event's data and status the connection's state. The stream closes when the component is disposed.

Import#

ts
import { useSSE } from "@shadow-js/dusk/client";

Signature#

ts
function useSSE<T = unknown>(url: string, options: UseSseOptions<T> = {}): StreamHandle<T>

Parameters#

Name Description
url The stream URL.
options Parse, headers, reconnection and fetch.

Returns#

The reactive handle.

Examples#

ts
const prices = useSSE<Price>("/prices");
return <p>{prices.data()?.value}</p>;