Optional
autoControls whether the hook should automatically enter presence when the component mounts and the room becomes attached, and automatically leave presence when the component unmounts.
Also controls whether the hook will automatically re-enter presence if the room is detached and then re-attached.
Important If UsePresenceResponse.leave is called, then the hook will NOT auto-enter. To re-enable auto-enter behavior, you must call UsePresenceResponse.enter or UsePresenceResponse.update. When set to false, you have full manual control over entering and leaving presence.
Defaults to true if not provided.
Optional
initialThe initial data to enter the room with when auto-entering (autoEnterLeave=true). Any JSON serializable data can be provided.
This data is only used for the initial auto-enter when the component mounts. Changes to this value
after the first render are ignored. To update presence data after the initial enter, use the
update
or enter
methods returned by the hook.
// This will cause the hook to auto-enter presence with the provided data
// autoEnterLeave is implicitly true
const { presence, update } = usePresence({
initialData: { status: 'online', lastSeen: Date.now() }
});
// Subsequent data updates must be done via calls to enter/update
await update({status: 'away'});
Optional
onRegister a callback for when the connection status to Ably changes.
Object representing the change in connection status.
Optional
onRegister a callback to detect and respond to discontinuities. For example, you might choose to fetch missing messages.
Optional
onRegister a callback for when the room status changes.
Object representing the change in room status.
The options for the usePresence hook.