Optional
Readonly
connectionIf there's a connection error it will be available here.
Readonly
connectionProvides the connection status of the Ably connection.
Readonly
enterA shortcut to the Presence.enter method, which can be used to manually enter presence when
autoEnterLeave
is false, or to explicitly re-enter presence with new data.
This is a stable reference and will not be changed between renders for the same room.
Important When called, if UsePresenceParams.autoEnterLeave is set to true, the hook will attempt to auto-enter presence automatically when conditions are met.
Method to join room presence, will emit an enter event to all subscribers. Repeat calls will trigger more enter events.
Optional
data: JsonObjectThe users data, a JSON serializable object that will be sent to all subscribers.
or upon failure, the promise will be rejected with an Ably.ErrorInfo object which explains the error.
Readonly
leaveA shortcut to the Presence.leave method.
This is a stable reference and will not be changed between renders for the same room.
Important When called, this will prevent the hook from automatically re-entering presence, even when autoEnterLeave
is true.
This is useful for manually controlling when presence is left.
Method to leave room presence, will emit a leave event to all subscribers. If the user is not present, it will be treated as a no-op.
Optional
data: JsonObjectThe users data, a JSON serializable object that will be sent to all subscribers.
or upon failure, the promise will be rejected with an Ably.ErrorInfo object which explains the error.
// Manual control over presence with conditional logic
const { enter, leave } = usePresence({ autoEnterLeave: false });
useEffect(() => {
if (effectCondition) {
enter({ status: 'active' });
}
return () => {
if (effectCondition) {
leave();
}
};
}, [effectCondition, enter, leave]);
// Enter presence automatically with some initial data
const { leave, enter } = usePresence({ initialData: { status: 'online' } });
// Leave presence explicitly, disabling auto re-entry
await leave();
// Re-enter presence again, re-enabling auto-entry if selected in the hook
await enter({ status: 'online again' })
Readonly
myThe current presence state of this client.
Optional
error?: ErrorInfoIndicates if an error occurred while trying to enter or leave presence.
Indicates if the user is currently present in the room.
Optional
Readonly
roomIf there's an error with the room it will be available here.
Readonly
roomProvides the status of the room.
Readonly
updateA shortcut to the Presence.update method.
This is a stable reference and will not be changed between renders for the same room.
Important When called, if UsePresenceParams.autoEnterLeave is set to true, the hook will attempt to auto-enter presence automatically when conditions are met.
Method to update room presence, will emit an update event to all subscribers. If the user is not present, it will be treated as a join event.
Optional
data: JsonObjectThe users data, a JSON serializable object that will be sent to all subscribers.
or upon failure, the promise will be rejected with an Ably.ErrorInfo object which explains the error.
Common status variables for chat features. Most hooks in this library implement this interface.