Examples
Who's Online
A minimal "who's viewing this page" widget using usePresence().
This example shows a row of colored avatar circles for every user currently on the page. It uses usePresence() and useMyPresence() and is under 50 lines of application code.
The apps/demo-presence app in the monorepo is a standalone Next.js app with this exact widget. View on GitHub.
The widget
Wiring it up
Key patterns
- Local user first: the widget includes yourself using
useMyPresence(), so the count always shows "1 viewing" even when alone, not "0 viewing." usePresence()excludes you:othersonly contains other users. We prepend ourselves fromuseMyPresence()to build the fullalllist.- Overlapping avatars:
marginLeft: -8overlaps the circles.zIndex: all.length - iensures the first avatar (you) is on top. - Initials fallback: if no avatar image is available, show the user's initials derived from their
name.