I'm currently learning how to use WebSocket with React! It's super great!
I learned this particular code from this Medium article.
I did update the client side to use hooks but that's about the only change I've made so far. More to come as I continue learning WebSocket.