Recently I had to consume a WebSocket API in a React application I was working on, So in this article, I will briefly explain how to use it in a Re...
For further actions, you may consider blocking this person and/or reporting abuse
My experience about WebSocket + React is implementing the connection in Redux middleware, including all the received event handler to dispatch Redux action automatically and to it has to do.
And dispatching a action like:
{
type: "SOCKET_XXXXXX"
}
to send event from client to server.
I'll try your solution for next time, it seems really work.
Thanks for share.
Hello Nero!
Thanks for taking your time to write this post.
Can you consider writing one with websockets + subscription? For example you connect to ws://localhost/something and subscribe to /posts/get?
Alright, will look into it.
Thanks Djordje.
What's up with mixing
var
andlet
instead of just usingconst
?What npm package to install for this?
Mine works without any packages.
You don't need to install any packages. It works without any packages
This looks good but unfortunately does not work if you try to pass
ws
to more than one child component.I find that the first child ends up not receiving any data.
Would you have a solution for this?
You can use react-websocket npm package to easily reconnect
Nice article bro, helped me a lot. Thanks.
Nice article, thank you.