Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda