Search for users in your groups

Ask the Community

Filter users down using various options


Overview #

This method allows searching for users with various options. Using the searchQuery will filter users by what their name start with. If no options are passed, a list of users will be returned.
React:
// Will return a list of users starting with 'al';
import { user } from '@cord-sdk/react';

const searchResults = useSearchUsers({ searchQuery: 'al' });

return (
  <div>
     {!searchResults && "Loading..."}
     {searchResults &&
       searchResults.users.map((user) => (
         <div key={user.id}>
           <p>User name: {user.name}</p>
          </div>
       ))}
  </div>
);
Vanilla JavaScript:
// Will return a list of users with names beginning with 'al'
await window.CordSDK.user.searchUsers({ searchQuery: 'al', groupID: 'my-group-id'}));
// Will return a list of users starting with 'al';
import { user } from '@cord-sdk/react';

const searchResults = useSearchUsers({ searchQuery: 'al' });

return (
  <div>
     {!searchResults && "Loading..."}
     {searchResults &&
       searchResults.users.map((user) => (
         <div key={user.id}>
           <p>User name: {user.name}</p>
          </div>
       ))}
  </div>
);
Copy

Available Data #

The API provides an object which has the following fields:


users #

ClientUserData[]

This is an array of objects, each of which has the following fields:


id #

string
The user's ID. This is unique within a project.

name #

string | null
The user's name.

shortName #

string | null
The user's short name. In most cases, Cord components will prefer using this name over name when set.

displayName #

string
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.

secondaryDisplayName #

string
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.

profilePictureURL #

string | null
A URL to the user's profile picture.

metadata #

EntityMetadata
Any metadata that has been set for the user.

What this function returns #

A promise that resolves to into an object with users which is a list of users in the group. This is a one time return.

Arguments this function takes #


options #

optional
ReactSearchUsersOptions

This is an object with the following fields:


searchQuery #

optional
string
The string to match the start of a user's name.

groupID #

optional
string
The group to search within. The viewer must be a member of the group in order to receive its data.

sortBy #

optional
SearchUsersSortByLocation
Sort users in order of when they visited the location.

This is an object with the following fields:


type
required
"location"

location
required
Location

sortDirection #

optional
"ascending" | "descending"
This option controls the direction that sortBy sorts. Combined with sortBy, it determines which searched users are "first".
It's a string enum which can have one of the following values:
ascending: sort users who have not visited the location first in the list, followed by those who visited a long time ago, followed by those who visited recently.
descending: sort users who have recently visited the location first in the list, followed by those who visited a long time ago, followed by those who have not visited the location at all.
If unset, defaults to descending.

skip #

optional
boolean
When set to true, prevents the execution of any operations within the hook.

Not finding the answer you need? Ask our Developer Community

Ask Cordy