title: Auto refresh JSON data on an set interval in React Native using React Hooks
body: <p>I'm working on a React Native app for a radio station which displays song &amp; artist info from a JSON url. How can I get the info to update/fetch every minute or so? I've tried a few variations of using setInterval, but can't seem to get it to work in my functional component. I'm guessing it's because I'm trying to use setInterval with an async function..? Thanks in advance!</p>
  
  <pre><code>  const [track, setTrack] = useState({});
  
    async function fetchData() {
      const res = await fetch(" my API url ");
      res
        .json()
        .then(res =&gt; setTrack(res.data[0].track.title))
        .catch(err =&gt; setErrors(err));
    }
  </code></pre>
  
  <pre><code>  useEffect(() =&gt; {
        fetchData();
    });
  </code></pre>
  
  <pre><code>&lt;Text&gt;{track}&lt;/Text&gt;
  </code></pre>