Rxova
Skip to content

useClientId

function useClientId(options?): string;

This client’s own id on the presence bus (matches patch origin ids).

Read through useSyncExternalStore rather than returned straight from render, because the id is minted per environment: a server would render one value and the browser a different one, and any component that puts it in the DOM would mismatch on hydration. The server snapshot is a constant empty string, which React also uses for the client’s hydrating render, so markup matches; the real id arrives in the commit straight after. Treat '' as “not known yet”.

ParameterType
options?{ name?: string; }
options.name?string

string