title: How to fetch featured media by post id using function
body: <p>I am working on a Gutenberg custom block, but I'm trying to put it to fetch featured media by post id using the function. It does not work for me. What is wrong with the below code.
  I don't make sense. Need a little help!</p>
  <pre><code>const getFeaturedMediaById = (featuredMediaId) =&gt; {
          const media = useSelect(
              ( select ) =&gt;
                  featuredMediaId &amp;&amp; select( 'core' ).getMedia( featuredMediaId ),
              [ featuredMediaId ]
          );
              return media;
  };
  const featured_media = getFeaturedMediaById(100);
  </code></pre>
  <p>Console error:</p>
  <pre><code>Uncaught Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings. 
      at Object.S (react-dom.min.js?ver=16.9.0:78)
      at useCallback (react.min.js?ver=16.9.0:31)
      at Module.Fe (data.min.js?ver=75f90354ddff4acd5b0b4026454037ca:2)
      at getFeaturedMediaById (&lt;anonymous&gt;:2:35)
      at &lt;anonymous&gt;:1:1
  </code></pre>