Skip to content
Apps— browse docs
On this page

Step 5: Presence while drawing

A labelled cursor that traces the other person's live pen — the best presence demo on this site.

Getting Started's presence page shows a coloured facepile — who's in the document right now. That's four lines with useDocumentPresence, and a canvas gets it exactly the same way:

function PresenceStrip({ handle }) {
  const others = useDocumentPresence(handle).filter((p) => !p.isSelf)
  if (others.length === 0) return null
  return (
    <span style={{ display: "flex" }}>
      {others.map((p) => (
        <span key={p.userId} style={{ background: p.color /* … */ }}>
          {p.name.slice(0, 1).toUpperCase()}
        </span>
      ))}
    </span>
  )
}

Pull handle out of useDocument, thread it into Canvas, and render <PresenceStrip handle={handle} /> in the corner opposite the toolbar.

Add presence
src/codec.ts + src/tool.tsx Lines 102 to 115 and 158 highlighted.

Edit and the example re-runs. Tab indents; press Escape to leave the editor.

Running · your edits, live
Starting the example…

You should see: nothing changes visibly yet — there's only one of you in this pane. The demo below proves it with a second identity for real.

Two people, one pen each
Move your pointer inside a pane
Starting the example…

Move your pointer inside one pane. The other one draws a small labelled cursor at the exact same spot — because on a canvas, your pointer position is your pen. That cursor and the coloured chip in the corner are drawn by real Yjs awareness relayed between two independent document replicas, the same mechanism Getting Started's presence page teaches — nothing here is a setInterval standing in for a second person.

Recap

  • useDocumentPresence(handle) lists who's in the document right now — the same hook, whatever the surface.
  • On a canvas specifically, the platform's cursor overlay traces the collaborator's actual pointer — their live pen, not a generic mouse icon.
  • Presence never touches your document. It's ephemeral, and it's drawn by the surface around your tool, not by sketchTool itself.

Next steps