Skip to content

Instantly share code, notes, and snippets.

Forked from zpao/gist:5686416
Last active June 3, 2022 06:37
What would you like to do?
/** @jsx React.DOM */
var MyRootComponent = React.createClass({
getInitialState: function() {
return {perMinute: '-', perDay: '-'};
componentDidMount: function() {
var socket = io.connect(this.props.url);
socket.on('business.clickout', this.setState.bind(this));
render: function() {
return <MyComponent perMinute={this.state.perMinute} perDay={this.state.perDay} />;
var MyComponent = React.createClass({
render: function() {
var perMinute = this.props.perMinute;
var perDay = this.props.perDay;
return (
<p>last Minute: {perMinute}</p>
<p>today: {perDay}</p>
<MyRootComponent url="http://localhost:3000" />,
Copy link

This is the sort of thing I am trying to do myself, I figured I should connect on my root component, but how would you pass the socket down to children components so that they may listen on specific channels?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment