score:0

useEffect(() => {
  const failToJoin = () => {
    setFailedToJoin(true);
  };

  const navigateToLobby = ({ lobby_id }) => {
    navigate(`/${lobby_id}`);
  }

  socket.on('failed_to_join', failToJoin);
  socket.on('space_available', navigateToLobby);

  return () => {
    socket.off('failed_to_join', failToJoin);
    socket.off('space_available', navigateToLobby);
  };
  // eslint-disable-next-line
}, [socket]);

Related Query

More Query from same tag