javascript - 如何检查我的用户是否已连接?
问题描述
我做了一个反应钩子来返回这个库的客户端,在这个钩子中,我还连接了用户。
useEffect((): any => {
async function getSub() {
const {
data: { createSupportChatSubscription },
} = await getSubscription();
return createSupportChatSubscription.subscription;
}
getSub().then(async (res: ISubscription) => {
const chatClient = StreamChat.getInstance(process.env.REACT_APP_STREAM_ID as string);
await chatClient.connectUser(
{ id: currentUser.id, name: currentUser.name },
res.token.token
);
setChannelResponse({
channelId: res.channelId,
channelType: res.channelType,
});
setClient(chatClient);
});
return () => client?.disconnectUser();
}, [getSubscription, client, currentUser.id, currentUser.name, userId]);
使用这个钩子时,我倾向于得到这个警告:
Consecutive calls to connectUser is detected, ideally you should only call this function once in your app.
我正在尝试查看聊天客户端是否有任何东西可以检查是否有连接,所以我不必经常打电话connectUser
。
解决方案
推荐阅读
- c++ - C11 和 switch-case 标签中的常量表达式求值
- python - Pandas 数据透视表以 Excel 分隔表
- javascript - React 异步函数不是函数
- c# - 捕获异步操作异常不起作用
- go - 如何检查是否已设置 int 变量?
- python - 发送请求中的证书错误
- python - 使用 python 从 10 GB 的单行日志文件中过滤所有 IP 地址
- android - OkHttp3 类未找到异常但存在于 apk 的 dex 文件中
- excel - 使用自定义公式的 Excel 数据约束错误
- exiftool - 在 exiftool -if 条件下使用变量