I'm facing an issue with initializing CometChat in a React application.
The error I'm getting is:
Error: Cannot find name 'setCometChat'. Did you mean 'CometChat'?
'CometChat' is declared here.
I have a useEffect
for initialization:
useEffect(() => {
initCometChat();
// ...
}, []);
And here's the initCometChat
function:
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/cordova-ionic-chat');
const appID = `${process.env.REACT_APP_COMETCHAT_APP_ID}`;
const region = `${process.env.REACT_APP_COMETCHAT_REGION}`;
const appSetting = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region).build();
CometChat.init(appID, appSetting).then(
() => {
console.log('CometChat was initialized successfully');
setCometChat(() => CometChat);
},
error => {
}
);
};
I tried using the passed-in setter function like this:
setCometChat(CometChat);
But it's not working.