Skip to main content
@paddock/react binds the browser client to React 18 or 19 with one hook, useSession, and one provider, PaddockProvider.

Install

It depends on @paddock/client and takes react as a peer dependency.
@paddock/react is not on npm yet. Until it is published, build it from the sdk/js workspace of the paddock repository.

useSession

useSession(sessionId, options) returns the session’s SessionState with two functions:
  • Shared connections. Hooks with the same base URL, token, and session ID share one handle: the stream opens with the first mounted hook and closes with the last. The base URL is compared as given, so a hook that omits it and one that names the default URL do not share.
  • Remounts are cheap. The page keeps every handle and its state, so a component that remounts resumes the stream without reloading the history.
  • Server rendering. During server rendering the hook returns the empty initial state and makes no request; the browser loads the session after hydration.
  • New token, new connection. Passing a new token opens a new connection with it. Do that when connection is closed because the token expired.

PaddockProvider

PaddockProvider supplies the base URL every useSession below it uses unless its own options name one:
For a complete chat application, see Chat app with React.