Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created October 10, 2021 16:41
Show Gist options
  • Save hieptl/ec5164216aa69d280d5bc4f64b153281 to your computer and use it in GitHub Desktop.
Save hieptl/ec5164216aa69d280d5bc4f64b153281 to your computer and use it in GitHub Desktop.
Home.js - Search Data - React Native Gifted Chat App
...
const searchUsers = () => {
if (cometChat) {
const limit = 30;
const usersRequestBuilder = new cometChat.UsersRequestBuilder().setLimit(limit);
const usersRequest = keyword ? usersRequestBuilder.setSearchKeyword(keyword).build() : usersRequestBuilder.build();
usersRequest.fetchNext().then(
userList => {
/* userList will be the list of User class. */
/* retrived list can be used to display contact list. */
setData(() => userList);
},
error => {
}
);
}
};
const searchGroups = () => {
const limit = 30;
const groupRequestBuilder = new cometChat.GroupsRequestBuilder().setLimit(limit);
const groupsRequest = keyword ? groupRequestBuilder.setSearchKeyword(keyword).build() : groupRequestBuilder.build();
groupsRequest.fetchNext().then(
groupList => {
/* groupList will be the list of Group class */
/* you can display the list of groups available using groupList */
setData(() => groupList);
},
error => {
}
);
};
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment