react-websocket
react-websocket
is a simple to use component for ReactJS applications to setup websocket communication.
Note: This component no longer active development. After +1 year my opinion handling websockets via component is not efficient way.
https://github.com/lukeed/sockette
Consider to use this oneInstalling
npm install --save react-websocket
Usage
; ; Component { superprops; thisstate = count: 90 ; } { let result = JSON; this; } { return <div> Count: <strong>thisstatecount</strong> <Websocket url='ws://localhost:8888/live/product/12345/' onMessage=thishandleData/> </div> ; } ;
Properties
url
required The url the websocket connection is listening to.
onMessage
required
The callback called when data is received. Data is JSON.parse
'd
onOpen
The callback called when the connection is successfully opened.
onClose
The callback called when the connection is closed either due to server disconnect or network error.
debug
default: false Set to true to see console logging
reconnect
default: true
accelerated reconnection time