- Notifications
You must be signed in to change notification settings - Fork5
PlatziDev/socket.io-react
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A High-Order component to connect React and Socket.io easily.
import{SocketProvider,socketConnect,}from'socket.io-react';
import{SocketProvider}from'socket.io-react';importiofrom'socket.io-client';importAppfrom'./containers/App';constsocket=io.connect(process.env.SOCKET_URL);socket.on('message',msg=>console.log(msg));constDOMNode=document.getElementById('renderTarget');render(<SocketProvidersocket={socket}><App/></SocketProvider>,DOMNode);
socketproperty isfalseby default.
import{socketConnect}from'socket.io-react';functionApp(props){functionsendMessage(){props.socket.emit('message','Hello world!');}return(<buttononClick={sendMessage}> Send!</button>);}exportdefaultsocketConnect(App);
socketConnectcan be used as a decorator (usingbabel-plugin-transform-decorators-legacy)
About
A High-Order component to connect React and Socket.io easily
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.