コンテンツにスキップ

Function: usePresence()

このコンテンツはまだ日本語訳がありません。

usePresence(options): UsePresenceResult

Defined in: react/src/use-presence.ts:83

React hook that subscribes to plasma presence for a room and returns the live peer list. Wraps createWebSocketSubscription so callers don’t have to imperatively wire it into createPlasmaClient when they only care about presence.

Presence changes trigger a re-render with the full snapshot every time. If you need to react to join vs leave individually, diff all in a useEffect.

const { peers, me, connecting } = usePresence({
url: "wss://api.example.com/sync/coordinator",
room: `doc-${docId}`,
token: env.PLASMA_COORDINATOR_TOKEN,
userInfo: { name: user.name, colour: user.colour },
})
return <AvatarList peers={peers} me={me} connecting={connecting} />

UsePresenceOptions

UsePresenceResult