react-socket-io-client
v1.1.1
Published
Socket.IO client component for React and React Native
Downloads
12
Readme
react-socket-io-client
Socket.IO client component for React and React Native
Install
$ npm i react-socket-io-client --save
Simple Usage
import * as React from "react"
import {SocketConnect,SocketEvent} from "react-socket-io-client"
class Example extends React.Component{
render(){
return (
<SocketConnect url={"YOUR SOCKET URL"}>
<ScoketEvent name={"YOUR EVENT"} callback={()=>null}></ScoketEvent>
</SocketConnect>
);
}
}
Table Content
SocketConnect
props
url
stringoptions?
Objectevent?
signature
methods
getSocketInstance
()=>void 获取socket实例
SocketEvent
props
name
stringcallback
Function
withSocket
如果要在组件内通过props.socket
访问socket实例可以使用withSocket
来实现.前提是组件必须是<SocketConnect>
的子组件,
import {withSocket} from "react-socket-io-client"
@withSocket
class Test extends React.Component{
...
}