New course! Every coder should learn Generative AI!
Try a free lesson+ 5
I don't know if there is any separate way of writing JavaScript code in React.js
This seems okay.
+ 5
Coder check these socket implementations
Using HOC (library)
https://www.npmjs.com/package/socket.io-react
Using Context API
https://itnext.io/how-to-use-a-single-instance-of-socket-io-in-your-react-app-6a4465dcb398
Using plain functions
https://medium.com/dailyjs/combining-react-with-socket-io-for-real-time-goodness-d26168429a34
And finally, a small tutorial:
https://dev.to/captainpandaz/a-socket-io-tutorial-that-isn-t-a-chat-app-with-react-js-58jh
Although this tutorial only show listening to the server, it is still a very nice and original example
+ 4
Nice implementation of socket.io on react👍🌷
I think you should update the date data through the state of react, let the virtual dom handling the dom update.
Here i tried to adding your socket function to a react hooks with useState and useEffect to control the state update.
https://code.sololearn.com/WRJgFWJM7kZg/?ref=app