Create a gist now

Instantly share code, notes, and snippets.

/** @jsx React.DOM */
var MyComponent = React.createClass({
getInitialState: function() {
// set up the initial state. used for "logical" initialization code
return {perMinute: '-', perDay: '-'};
componentDidMount: function() {
// fired only once, when the component is added to the DOM
// used for initialization code that has "side effects" i.e. i/o, jquery plugins, etc
var socket = io.connect(this.props.url);
// assuming that the data coming back has perMinute and perDay keys, this will just work.
// if it doesn't, just pass a callback that will eventually call setState() with the right
// values
socket.on('business.clickout', this.setState.bind(this));
render: function() {
var perMinute = this.state.perMinute;
var perDay = this.state.perDay;
return (
<p>last Minute: {perMinute}</p>
<p>today: {perDay}</p>
<MyComponent url="http://localhost:3000" />,

This comment has been minimized.

Show comment
Hide comment

evgenosiptsov Jun 12, 2016



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