I have a strategic question.
I want to change the data on my website using signalR and display the changed data using a reaction. My question is: How do I bind data between the signal and respond?
My first clue is this:
signalR:
chat.client.addMessage = function (name, message) { chatHistory.push({ Author: name, Text: message });
react:
var CommentList = React.createClass({some class here}); var CommentBox = React.createClass({ componentRefresh: function () { this.setState({ data: chatHistory }); }, getInitialState: function () { return { data: chatHistory }; }, componentDidMount: function () { this.componentRefresh(); setInterval(this.componentRefresh, this.props.interval); }, render: function () { return ( React.DOM.div(null, CommentList({ data: this.state.data }) ) ); } }); React.renderComponent( CommentBox({ interval: 2000 }), document.getElementById('content') );
in the response of the commentBox component I pass the global chat history and request a new value every 2 seconds.
Is there a more elegant way to do this? and how to avoid redrawing the CommentBox if the chatHistory variable has not been changed?
source share