How to use the presence API to observe users present at a location
Overview
This method allows you to observe users who are present at a particular location, including live updates.
import{ presence }from'@cord-sdk/react';const result = presence.useLocationData(location, options);
Copy
Usage
import{ presence }from'@cord-sdk/react';const present = presence.useLocationData({page:"https://cord.com",block:"id123"},{exclude_durable:true},);return(<>{present.map((user)=><div>{user.id} is present!</div>)}</>);
Copy
Available Data
The API provides an array of objects, each of which has the following fields:
durable
optional
{
location: Location;
timestamp: Date;
}
Contains information about the user's durable presence. Undefined if the user does not have a durable presence set. The location and timestamp will be for the user's most recently-set matching durable presence record (which may not be for the requested location if using the partial_match option).
ephemeral
required
{
locations: Location[];
}
Contains information about the user's ephemeral presence. The location array can be empty if the user is not currently present at the requested location.
id
required
UserID
The user ID of the user this presence information is for.
What this function returns
An array of objects, one for each user present at the location which was passed to this hook. Each object will contain the fields described under "Available Data" above. The component will automatically re-render if any of the data changes, i.e., this data is always "live".