1👍
✅
You should bind your request
to LChart
component.
var LChart = React.createClass({
getInitialState: function() {
return {
rows: [],
}
},
componentWillMount: function () {
var _this = this;
var request = function () {
this.props.onUpdate();
$.post("/url" ,{'start':this.props.sTime, 'end':this.props.eTime }, function (result) {
_this.setState({
rows: result.data
});
});
setTimeout(request, 10000);
};
request = request.bind(this);
request();
},
render: function() {
return (
<div id="chart_widget" >
<Chart chartType="LineChart"
rows={this.state.rows}
columns={this.props.columns}
options={this.props.options}
width={this.props.width}
height={this.props.height} />
</div>
);
}
});
Besides, in your parent components, declare the new Date
outside of the setState
call.
Source:stackexchange.com