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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.