#Presence Component List Room
4 messages · Page 1 of 1 (latest)
Hi @steep haven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The knowledge sources only briefly mention this functionality and don’t show a full example of using listRoom (or similarly named functions) together with the usePresence React hook, so I can’t give you an exact, documented pattern. However, here’s what is clear from the docs:
- The
@convex-dev/presenceConvex component exposes extra server-side helpers “for querying presence for a given user or room,” and explicitly calls out alistUserfunction as an example. [Presence component] - On the client, the most common pattern is to use the
usePresencehook, which handles heartbeats and disconnects and gives you a live-updating list of users in a room. [Presence component]
Putting those together:
-
usePresenceis for live room presence in React.
You call it like:import { api } from "../convex/_generated/api"; import usePresence from "@convex-dev/presence/react"; const presenceState = usePresence(api.presence, "my-chat-room", userIdOrName);This already subscribes you to presence changes for that room and returns the current list of users (plus handles heartbeats). [Presence component]
-
listRoom-style helpers are server-side utilities.
The docs say the component interface “includes additional functions for maintaining presence state and for querying presence for a given user or room,” and givelistUseras an example. [Presence component]
By analogy, alistRoomfunction would be called from Convex query functions (or mutations) on the server, not directly from the ReactusePresencehook. -
How to combine them conceptually:
- Use
usePresencein React whenever you want a live list of users in a specific room. - If you need a server-side query that lists presence for a room (e.g., for admin tools, batch processing, or non-reactive contexts), you’d:
- Import the
Presencehelper in a Convex query. - Call its
listRoom/room-listing helper there. - Then, from React, call that query with
useQueryif you need that data in the UI. [Presence component]
- Import the
- Use