react-socket-io-client

1.1.1 • Public • Published

react-socket-io-client

Socket.IO client component for React and React Native

npm version npm license npm download npm download Build Status Coverage Status

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 string
  • options? Object
  • event? signature

methods

  • getSocketInstance ()=>void 获取socket实例

SocketEvent

props

  • name string
  • callback Function

withSocket

如果要在组件内通过props.socket访问socket实例可以使用withSocket来实现.前提是组件必须是<SocketConnect>的子组件,

import {withSocket} from "react-socket-io-client"

@withSocket
class Test extends React.Component{
    ...
}

Readme

Keywords

Package Sidebar

Install

npm i react-socket-io-client

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

10.9 kB

Total Files

6

Last publish

Collaborators

  • m860