I asked the question of regularly receiving data from the server. On Habré, I found how to implement polling: a couple of methods are added to the component:
loadNewDataFromServer: function() { $.ajax({ url: this.props.url, dataType: 'json', cache: false, success: function(data) { this.setState({data: data}); }.bind(this), error: function(xhr, status, err) { console.error(this.props.url, status, err.toString()); }.bind(this) }); }, componentDidMount: function() { this.loadNewDataFromServer(); setInterval(this.loadNewDataFromServer, this.props.pollInterval); }
Question 1: I understand correctly, before removing a component from the DOM (when switching the user's attention to another component that is completely independent of the data received), to save traffic, you need to stop the requests as follows:
componentWillUnmount(){ // подскажите, что здесь? }
Question 2: m., Will you advise any other methods of updating data on the client?
Thank you in advance.
this.timer = setInterval(...
, in componentWillUnmount () stop this timerclearInterval( this.timer)
. - Sergiks