Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/platzidev/socket.io-react

A High-Order component to connect React and Socket.io easily
https://github.com/platzidev/socket.io-react

decorators high-order-component react react-components socket socket-io

Last synced: about 1 month ago
JSON representation

A High-Order component to connect React and Socket.io easily

Awesome Lists containing this project

README

        

# socket.io-react
A High-Order component to connect React and Socket.io easily.

## API
```javascript
import {
SocketProvider,
socketConnect,
} from 'socket.io-react';
```

### SocketProvider(socket?)
```javascript
import { SocketProvider } from 'socket.io-react';
import io from 'socket.io-client';

import App from './containers/App';

const socket = io.connect(process.env.SOCKET_URL);
socket.on('message', msg => console.log(msg));

const DOMNode = document.getElementById('renderTarget');

render(


,
DOMNode
);
```
* `socket` property is `false` by default.

### socketConnect(Target)
```javascript
import { socketConnect } from 'socket.io-react';

function App(props) {
function sendMessage() {
props.socket.emit('message', 'Hello world!');
}

return (

Send!

);
}

export default socketConnect(App);
```
* `socketConnect` can be used as a decorator (using [**babel-plugin-transform-decorators-legacy**](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy))