Skip to content

Instantly share code, notes, and snippets.

@xiujunma
Created July 4, 2015 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiujunma/cf0c0c47d5022630b9bf to your computer and use it in GitHub Desktop.
Save xiujunma/cf0c0c47d5022630b9bf to your computer and use it in GitHub Desktop.
var Page = React.createClass({
getInitialState: function() {
return {word: null};
},
componentDidMount: function() {
var ws = new WebSocket("ws://url.com/ws");
var self = this;
ws.onmessage = function(msg) {
self.setState({word: msg});
}
},
render: function() {
return (<span>{this.state.word}</span>)
}
});
React.render(<Page />,
document.body
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment