title: How to call a function every minute in a React component?
body: <p>I make a table to get stock price quotes, it works well, but when I try to put a function include setState in the component, it falls into an infinite loop, it triggers setState and re-render immediately and triggers again.</p>
  <p>How can I call this function without triggering an infinite loop when I load this component?
  I would to call the function every 10 seconds or every minute.</p>
  <pre><code>import React, { useState } from 'react'
  import api from '../../api'
  
  function CreateRow(props){
      
      const [stock, setStock] = useState({symbol:'',last:'',change:''})
      
  
      async function check() {
          const result = await api.getStock(props.item)
          console.log(props.item)
          const symbol = result.data.symbol
          const lastest = result.data.latestPrice
          const change = result.data.change
          setStock({symbol:symbol, lastest:lastest, change:change})
      }
  
  
      // check()   &lt;----------! if I call the function here, it becomes an infinite loop.
  
  
      return(
          &lt;tr&gt;
              &lt;th scope=&quot;row&quot;&gt;&lt;/th&gt;
              &lt;td&gt;{stock.symbol}&lt;/td&gt;
              &lt;td&gt;{stock.lastest}&lt;/td&gt;
              &lt;td&gt;{stock.change}&lt;/td&gt;
          &lt;/tr&gt;
      )
  }
  
  export default CreateRow
  </code></pre>