Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!