charleslxh / react-socket-io

A react provider for socket.io, http://socket.io/
Apache License 2.0
126 stars 31 forks source link

how to emit event #16

Open baikaifa opened 4 years ago

baikaifa commented 4 years ago

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

calix commented 4 years ago

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.