title: How to better setup fetch with useEffect?
body: <p>Im learning JS and React and I came to the code example below and some parts I don't understand properly. The second .then is inside useUffect is this ok, or it's better to be in getData func? Also in render there is data**?**.map and I don't understand why we need ?, is this ternary operator? Is so I thought that ternary operator requires : as a second parameter. Thanks in advance!</p>
  <pre><code>import React, { useState, useEffect } from &quot;react&quot;;
  
  const FetchData = () =&gt; {
    const [data, setData] = useState(null);
    const fetchURL = &quot;https://jsonplaceholder.typicode.com&quot;;
      
      const getData = () =&gt; fetch(`${fetchURL}/posts`)
          .then((res) =&gt; res.json());
  
      useEffect(() =&gt; {
          getData().then((data) =&gt; setData(data));
      }, []);
  
      return (&lt;div&gt;
          {data?.map(item =&gt; (
              &lt;ul&gt;
                  &lt;li&gt;{item.title}&lt;/li&gt;
            &lt;/ul&gt;
        ))}
    &lt;/div&gt;);
  };
  
  export default FetchData;
  </code></pre>