title: How to get helper function returning promise for React hook function
body: <p>I have the following React functional component with <code>useState</code> and <code>useEffect</code> hooks:</p>
  <pre><code>import React, { useState, useEffect } from 'react';
  import { requestInfo } from './helpers/helpers';
  
  const App = () =&gt; {
    const [people, setPeople] = useState([]);
  
    useEffect(() =&gt; {
      requestInfo('people', '82')
        .then(results =&gt; setPeople(results))
    }, []);
  
    return (
      &lt;p&gt;We have {people.length} people in this game.&lt;/p&gt;
    );
  }
  
  export default App;
  </code></pre>
  <p>In <code>helpers.js</code> I have this function:</p>
  <pre><code>export const requestInfo = (resource, quantity) =&gt; {
    fetch(`https://swapi.dev/api/${resource}/?results=${quantity}`)
      .then(response =&gt; response.json)
      .then(data =&gt; data.results)
  }
  </code></pre>
  <p>I don't have much experience of writing asynchronous functions that call APIs, but I've looked at other Q&amp;As on this website that said in situations like this I need to have the helper function return a promise, then have the code that calls the helper function do something with the outcome of the promise, in this case pass it to the <code>setPeople</code> hook state setter function.</p>
  <p>I'm currently getting the error <code>TypeError: Cannot read property 'then' of undefined</code> from within my call to <code>useEffect</code>.</p>
  <p>I think the endpoint is correct because this command works and returns the expected data when run in my terminal:</p>
  <pre><code>curl https://swapi.dev/api/people/\?results\=82
  </code></pre>
  <p>I'd be very grateful if someone can show me how to modify one or both of my functions to make this work.</p>