Skip to content

usePlayerIdentity

usePlayerIdentity() returns the local player’s identity from the playhtml context.

import { usePlayerIdentity } from "@playhtml/react";

function Profile() {
  const { color, pid, name } = usePlayerIdentity();
  return <div style={{ color }}>{name ?? "anonymous"}</div>;
}
FieldTypeNotes
colorstringThe player’s cursor color.
pidstring | undefinedParticipant id (ECDSA public key). undefined until cursors sync.
namestring | undefinedThe player’s chosen name, if set.

Values update reactively. When the “we were online” browser extension is installed, it injects its identity via the playhtml:configure-identity event, and this hook reflects the extension’s color and PID automatically.

Requires a PlayProvider with cursors: { enabled: true }.