title: How to load data every seconds automatically in react native?
body: <p>I would like to load data automatically every seconds.</p>
  
  <p>I use <strong>setinterval</strong> but it always said error like this</p>
  
  <p><strong>"TypeError: undefined is not a function (near '...this.state.forumContentData.map...')"</strong></p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>constructor(props) {
    super(props);
    this.state = {
      forumContentData: []
    }
  }
  
  componentDidMount() {
    // Set timer before going to the Next Action - Every Seconds
    this._interval = setInterval(() =&gt; {
      this.getForumContent();
    }, 1000);
  }
  
  componentWillUnmount() {
      clearInterval(this._interval);
  }
  
  getForumContent() {
    return fetch('http://' + ipAddress() + ':' + portAddress() + '/api/forum/view_thread', {
      method: 'GET',
      headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
      }
    })
    .then((response) =&gt; response.json())
    .then((responseJson) =&gt; {
      this.setState({forumContentData: responseJson}); // Get the data from API
    })
    .catch((error) =&gt; {
      //console.error(error);
  
      alert(error);
    });
  }
  
  render() {
  
    let forumContentResult = this.state.forumContentData.map((forumContentDataDetail, index) =&gt; {
        var forum_title = forumContentDataDetail.title;
  
        return (
          &lt;Text&gt;{forum_title}&lt;/Text&gt;
        );
    });
  
  
  }
  </code></pre>
  
  <p>What would be the best way to load data every seconds automatically in react native?</p>