title: Can you use an async function to set initial state with useState
body: <p>My component relies on local state (<code>useState</code>), but the initial value should come from an http response.</p>
  <p>Can I pass an async function to set the initial state? How can I set the initial state from the response?</p>
  <p>This is my code</p>
  <pre><code>  const fcads = () =&gt; {
      let good;
      Axios.get(`/admin/getallads`).then((res) =&gt; {
        good = res.data.map((item) =&gt; item._id);
      });
      return good;
    };
  
    const [allads, setAllads] = useState(() =&gt; fcads());
  </code></pre>
  <p>But when I try <code>console.log(allads)</code> I got result <code>undefined</code>.</p>