Install socket.io-client library
Copy and run following command at project’s root folder.
1 | npm i socket.io-client --save |
How to use
Import new library have installed to project
You need to import the correct path as below for this library to work.
1 | import io from 'socket.io-client/dist/socket.io'; |
Connect to socket server and listen event
You can make an connect to socket server in constructor function.
1 | constructor(props) { |
Function this.socket.on() to listen an event from socket server
Send an event and data to socket server
To call an event to socket server you can using emit function.
1 | this.socket.emit('event', data); |