Skip to content

Instantly share code, notes, and snippets.

@designviacode
Forked from tocttou/SocketProvider.jsx
Created June 19, 2017 22:53
Show Gist options
  • Save designviacode/c76b9958ab126fd381e13260077d3dc2 to your computer and use it in GitHub Desktop.
Save designviacode/c76b9958ab126fd381e13260077d3dc2 to your computer and use it in GitHub Desktop.
import React, { Component, PropTypes } from "react";
class SocketProvider extends Component {
constructor(props, context) {
super(props, context);
this.socket = context.socket;
}
render() {
return (
<span>
{React.cloneElement(this.props.children, {
...this.props,
...{ socket: this.socket }
})}
</span>
);
}
}
SocketProvider.contextTypes = {
socket: PropTypes.object.isRequired
};
export default SocketProvider;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment