Flock
Api referenceReact

FlockProvider

The React context provider that sets up the Flock connection and makes hooks available to child components.

<FlockProvider> creates the FlockClient, joins the specified room, and makes the connection available via React context so all child hooks (useCursors, usePresence, etc.) work without prop drilling.

Place it once near the top of your component tree, above any components that call Flock hooks.

import { FlockProvider } from "@xevrion/flock-react";
 
export default function App() {
  return (
    <FlockProvider
      serverUrl="wss://your-flock-server.com"
      roomId="my-room"
      userId="user-123"
      metadata={{ name: "Alice", color: "#7c5cff" }}
    >
      <YourApp />
    </FlockProvider>
  );
}

Props

FlockProviderProps extends FlockClientOptions and RoomOptions.

PropTypeRequiredDefaultDescription
serverUrlstringYesWebSocket URL of the Flock server
roomIdstringYesThe room to join
userIdstringYesYour user's unique identifier
metadataUserMetadataNo{}Initial presence metadata: name, color, avatar, plus any custom fields
apiKeystringNoAPI key, if the server requires one
interpolatebooleanNotrueEnable smooth cursor interpolation between received positions
interpolationMsnumberNo80The interpolation window in milliseconds. Larger = smoother but laggier
cursor.throttleMsnumberNo50Milliseconds between cursor update messages (~20/sec at default)
reconnect.maxAttemptsnumberNoInfinityMax reconnect attempts before giving up
reconnect.baseDelayMsnumberNo1000Initial reconnect delay
reconnect.maxDelayMsnumberNo30000Max reconnect delay
childrenReactNodeYesYour app content

Lifecycle

The provider creates a FlockClient and joins the room inside a useEffect. When the component unmounts it destroys the client and cleans up the WebSocket connection. The effect re-runs if serverUrl, roomId, or userId change.

Toggling interpolate or interpolationMs does not reconnect — those props are presentation-only and update in place.

TypeScript

import type { FlockProviderProps } from "@xevrion/flock-react";

On this page