Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created August 4, 2021 07:34
Show Gist options
  • Save hieptl/41162782cbb5b264747cce763993ad87 to your computer and use it in GitHub Desktop.
Save hieptl/41162782cbb5b264747cce763993ad87 to your computer and use it in GitHub Desktop.
Initialize CometChat - Facebook Clone
...
useEffect(() => {
// init cometchat pro.
initCometChat();
}, []);
/**
* init comet chat.
*/
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/chat');
const appID = `${process.env.NEXT_PUBLIC_COMETCHAT_APP_ID}`;
const region = `${process.env.NEXT_PUBLIC_COMETCHAT_REGION}`;
const appSetting = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region).build();
CometChat.init(appID, appSetting).then(
() => {
setCometChat(() => CometChat);
},
error => {
}
);
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment