title: React native: execute code once after component loded
body: <p>When my app start, I load a component called ListComponent that will get all the items list from the server and show them is a listView. I have a sideMenu with different categories. If the user choose one category, ListComponent is called again through stackNavigator but with different URl. In <code>ListComponent</code> my code looks like </p>
  
  <pre><code>class ListComponent extends Component {
    constructor(props) {
      super(props);
      this.state = {
        isLoading: true
      }
    }
  
  componentDidMount() {
  this.requestUrl(allItemsUrl)
  }
  
  componentWillUpdate(){
    const params = this.props.navigation.state.params;
  if(params.id == '1'){
      this.requestUrl(urlCategory1);
    }else if (params.id == '2'){
     //.....
    }
  }
  
  render() {
  
      if (this.state.isLoading) {
        return (
          &lt;View style={{flex: 1}}&gt;
            &lt;ActivityIndicator style={styles.activity}/&gt;
          &lt;/View&gt;
        );
      }
  
  // show the list with the selected category data
  </code></pre>
  
  <p><code>componentWillUpdate()</code> is called each time a new category is selected from the menu item. The problem is that when <code>componentWillUpdate</code> is called, the data is requested and then render is called again to render the new data, this will call <code>componentWillUpdate</code> again and create an infinite loop. But I didn't figured out what to use instead of <code>componentWillUpdate</code> to ensure that it will be called only one time when the category is selected from the <code>stackNavigator</code>. </p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I stopped the infinite loop by applying the suggested solution in comments and comparing the old and nextProps. I also changed componentWillUpdate to componentDidUpdate but now I started getting a warning </p>
  
  <blockquote>
    <p>Warning: In next release empty section headers will be rendered. In
    this release you can use 'enableEmptySections' flag to render empty
    section headers</p>
  </blockquote>
  
  <p>Do you know what is the problem?</p>