Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stomp auto make new connect after about 1 minute. #629

Open
KhanamDEV opened this issue Apr 26, 2024 · 1 comment
Open

Stomp auto make new connect after about 1 minute. #629

KhanamDEV opened this issue Apr 26, 2024 · 1 comment

Comments

@KhanamDEV
Copy link

Hi Development Team,
I have issue when config stomp in ReactJS
This is my config:

const [socketReservationClient, setSocketReservationClient] = useState<Client>(new Client({
        brokerURL: process.env.REACT_APP_SOCKET_URL,
        connectHeaders: socketHeaders,
        heartbeatIncoming: 60000,
        heartbeatOutgoing: 60000,
        onDisconnect: eve => {
            console.log("Disconnected")
        }
    }));

But when run it, every 1 minute or so the client will automatically connect and create a new websocket. I'm sure I didn't create any other code to add a new connection. How can I turn it off?

image

@kum-deepak
Copy link
Member

The issue most likely is caused the way useState works. It is not a bug. Using this library with React is tricky.

I usually do not program with React, and I do not use this library with React. So, I got someone to prepare a sample to use this library with React. This structure does not suffer from this problem. In addition, it also covers the case when child components use the client.

Please see https://github.com/stomp-js/rx-stomp-react-sample - start with src/App.js and the accompanying tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants