title: AJAX requests from a React component
body: <p>I am having a react component that looks something like this. It internally uses highcharts-react to render a chart by fetching a data from an API by supplying the API some of its state properties.</p>
  
  <pre><code>export default class CandlestickChart extends React.Component {
      constructor (props) {
          super(props);
          this.state = { 
              apiParam1: this.props.propData.param1,
              apiParam2: this.props.propData.param2,
              chartConfig: this.getChartConfig(this.props.apiParam1),
          };
      }
  
      componentDidMount() {
          this.renderChart();
      }
  
      render() {
          return (
              &lt;div className='col-lg-6'&gt;
                  &lt;div className='well'&gt;
                      &lt;ReactHighStock config={this.state.chartConfig} /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          );
      }
  
      renderChart() {
          var that = this;
          NanoAjax.ajax({
              url: 'myApi.com?param1=' + this.state.apiParam1 + '&amp;param2=' + this.state.apiParam2;
          }, function (statusCode, responseText) {
              //transform the data a bit
  
              var chartConfig = that.getChartConfig(that.state.apiParam1);
              chartConfig.series[0].data = chartData;
  
              that.setState({
                  chartConfig: chartConfig
              })
          });
      }
  
      getChartConfig(param1) {
          // returns HighCharts chartConfig object based on apiParam1
      }
  }
  </code></pre>
  
  <p>This works perfectly fine as long as the component is static, i.e., once the params are set during initial render, the parent control will never update it. Also, this approach is same as given in here : <a href="https://daveceddia.com/ajax-requests-in-react/" rel="nofollow noreferrer">https://daveceddia.com/ajax-requests-in-react/</a></p>
  
  <p>However, my requirement is that, the parent control can update the props <code>param1</code> and <code>param2</code> of this control, causing it to make a fresh ajax call with these values and re-render the chart with new data.</p>
  
  <p>How to approach this?</p>