Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

310
Visualizações
How do I check my user is already connected?

I made a react hook to return the client for this library, and in this hook, I'm also connecting the user.

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]);

when using this hook, I tend to get this warning:

Consecutive calls to connectUser is detected, ideally you should only call this function once in your app.

I'm trying to see if the chat client has anything to check if there's a connection so I don't have to constantly call connectUser.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda