socket.io-react

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

Showing:

Popularity

Downloads/wk

614

GitHub Stars

66

Maintenance

Last Commit

4yrs ago

Contributors

4

Package

Dependencies

0

Size (min+gzip)

0.9KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

socket.io-react

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

API

import {
  SocketProvider,
  socketConnect,
} from 'socket.io-react';

SocketProvider(socket?)

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(
  <SocketProvider socket={socket}>
    <App />
  </SocketProvider>,
  DOMNode
);
  • socket property is false by default.

socketConnect(Target)

import { socketConnect } from 'socket.io-react';

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

  return (
    <button onClick={sendMessage}>
      Send!
    </button>
  );
}

export default socketConnect(App);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial