=============================================================================================================================================> I...
For further actions, you may consider blocking this person and/or reporting abuse
I guess your code will create multiple instances of Websocket, you should put this in useEffect hook to avoid that
That's right. I will even go further and create a hook ( useWebsocket that uses useEffect internally) where you can pass the callback functions onopen and onmessage and returns a send function for instance or whatever you need from the hook.
Hey man, I wrote a reply to Vu's comment. Feel free to join the discussion :)
Every time the client receives new message =>
setBids
called => component rerender => create new instance of Websocket => create new connection (1 request in devtools). This's not good, right :)))This is my idea. You can check more in network tab in devtools and see the differents.
Hello, I have 4 components that I repeat the same method and it seems like each one waits its turn to display the data. I was wondering how to fix that, I guess you're taling about that? In my original code, I have useEffect in this manner :
What should I do to overcome the problem you mentioned?
if ((json.event = "data")) {
Why "=", and not "==="?
Because he's not using a linter?
That's why he gets a lot of unfiltered events.
Good question, that was some snippet I found while trying to figure out how to get started, and itseemed to work. I didn't even think about it. Will it cause any problems? It didn't so far...
This condition will always be true because the assignment operator is used instead of the comparison operator.
Gonna edit it (y)
Clear, concise and useful! Thanks for sharing. As others have mentioned using the useEffect hook is likely the best spot for initializing WS, but it adds additional code so 🤷♀️. In any case really great work
Sorry but this article has many technical errors.
Seems you've been aware about them yet you didn't correct the article.
True. I haven't touched websockets after writing this article though, worked on some other stuff and all. I'm thinking of trying to correct it as much as I can once I get the time to dive into websockets further.
I agree
Why use websocket and not socket.io? Just asking to exchange some dialog between the two.
To be honest, I'm not even sure what's the other one. I had 3 days to learn websockets and redux, so I went with that way.
What's the difference between the two? Why should I check socket.io?
Websocket is the native api from your browser whereas socket.io does not implent the same api although it can use websocket under the hood if the browser support it, besides it has the server version that helps the backend keep the same interface with the client and add extra features as authentication , etc.
Once the WebSocket server is created, we had to accept the handshake on receiving the request . dua to make someone call you
thank you so much !
helpful for my assignment