Skip to content

Socket join and socket.rooms not working #4575

Discussion options

You must be logged in to vote

Hey,
so when you use react with socketio, the problem is that every time the app re-renders, the clientID changes, so even if you are making the client join a room, when you emit the message to the room, your client has already updated and is now existing with a different id. So when messages are emitted, it does not reflect on the client side as the client is not really in the room.

I was facing the same issue and I solved it by manually setting the clientId and persisting it.

here's what I did

On the client side,

const socket = io.connect(socketInUse, {
    transports: ["websocket"],
    query: "clientId=" + customId,
  });

here socketInUse is the link of my backend and I am setting th…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@TheresaRoss
Comment options

@pushkarsingh019
Comment options

@darrachequesne
Comment options

@pushkarsingh019
Comment options

@darrachequesne
Comment options

Answer selected by TheresaRoss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants