Example code using websockets with ReactJS and Redux
Clone repo, then:
- install modules:
npm i - start website:
npm start
Don't forget to set your websocket url inside your environment file! (or, if you want to play around, use the test websocket serve available at https://socketsbay.com/test-websockets )
- all routes are wrapped in a
Websocketcomponent, so all other components can control/interact with the connection. - connect/disconnect to a websocket server via function call
- once connected, it will automatically reconnect should connection be terminated, unless told (via function call) to not reconnect (probably on session log out or something)
- incoming messages get propagated to
props.