react-socket-io icon indicating copy to clipboard operation
react-socket-io copied to clipboard

how to emit event

Open baikaifa opened this issue 5 years ago • 1 comments

I don't konw how to emit event,I konw use Event to revceive enent,but how to emit one thing?

baikaifa avatar May 09 '20 13:05 baikaifa

Had the same issue. Was able to access the emit method by attaching the context to the component:

SomeComponent.contextType = SocketContext;

And then in the component access emit via:

this.context.emit...

SocketContext can be imported from react-socket-io.

Emit is callable but I did not manage to get it working. Created my own React Context object instead and used the socket.io directly.

calix avatar May 09 '20 16:05 calix