DEV Community

Discussion on: How to prevent multiple socket connections and events in React

Collapse
 
the_riz profile image
Rich Winter

I was working with React and Socket.io and one of the warning messages I got from the React server suggested storing the socket reference in a useRef() hook, but honestly, I kind of like your solution more.

Another additional thought I've seen is to use the .context() API and serve the socket to all components through a Provider.