This method allows you to observe the members of a group the current user is a member of - either the current group the viewer is logged into, or, if specified as an option, another group the viewer is a member of.
React:
import { user } from '@cord-sdk/react';
const { groupMembers, loading, hasMore, fetchMore } = user.useGroupMembers();
return (
<div>
{groupMembers.map((groupMembers) => (
<div key={groupMembers.id}>
Group member ${groupMembers.id} is called ${groupMembers.name}!
</div>
))}
{loading ? (
<div>Loading...</div>
) : hasMore ? (
<div onClick={() => fetchMore(10)}>Fetch 10 more</div>
) : null}
</div>
);
Vanilla JavaScript:
const ref = window.CordSDK.user.observeGroupMembers(
({ groupMembers, loading, hasMore, fetchMore }) => {
console.log('Got a group members update:');
if (loading) {
console.log('Loading...');
}
groupMembers.forEach((groupMember) =>
console.log(`Group member ${groupMember.id} is called ${groupMember.name}!`),
);
if (!loading && hasMore && groupMembers.length < 25) {
// Get the first 25 group members, 10 at a time.
fetchMore(10);
}
},
{groupID: 'group123'}
);
import{ user }from'@cord-sdk/react';const{ groupMembers, loading, hasMore, fetchMore }= user.useGroupMembers();return(<div>{groupMembers.map((groupMembers)=>(<div key={groupMembers.id}>Group member ${groupMembers.id} is called ${groupMembers.name}!</div>))}{loading ?(<div>Loading...</div>): hasMore ?(<div onClick={()=>fetchMore(10)}>Fetch10 more</div>):null}</div>);
When this is true, Cord is in the process of fetching additional data from its backend. Once the fetch is complete, the additional items will be appended to the result list, and loading will become false.
Both the initial data load and a call to fetchMore will start a fetch and cause loading to become true.
Call this function to fetch additional data from Cord's backend. It takes a single argument, the number of additional items to fetch.
Once called, loading will become true while the data is fetched. Once the fetch is complete, the additional items will be appended to the result list, and loading will return to false.
This function returns a promise that is resolved once the fetch is complete.
If this is true, then the list of results is incomplete, and you need to call fetchMore to continue paginating through them. Once this becomes false, all results are available, and calls to fetchMore won't do anything.
The primary display name of the user. This is a readonly field that's provided as a convenience. Its value is the user's shortName or name, preferring shortName if both are set, or the string "unknown" if neither is set.
The secondary display name of the user, in cases where you might want to display a secondary name (such as in a subtitle). This is a readonly field that's provided as a convenience. Its value is the user's name or shortName, preferring name if both are set, or the string "Unknown" if neither is set.
The hook will initially return an empty array while the data loads from our API. Once it has loaded, your component will re-render and the hook will return an object containing the fields described under "Available Data" above.
The group to search for. The viewer must be a member of the group in order to receive its data. If omitted, the API will fetch the members of the group the viewer is currently logged in with, i.e. the one that is specified in their access token.