title: How to fetch data from an endpoint with in ReactJS
body: <p>enter image description hereI want to fetch data using this way: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React, { useState, useEffect } from 'react';
  
  const Home = () =&gt; {
  
    useEffect (async () =&gt;{
      const response = await fetch('http://localhost:4000/user')
        const myJson = await response.json();
        console.log(JSON.stringify(myJson));
    })
   
    return(
      &lt;div&gt;
        &lt;h1&gt;Home Page&lt;/h1&gt;
      &lt;/div&gt;
    )
  }
  
  export default Home;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The result of localhost:4000 (generated with node js) is: <code>{ _id: 5da4a2066f90a24d4f82787a, name: 'Gregor', email: 'test@eee.com', age: 3, hasCar: false, favColors: [ 'green', 'red' ] }</code>. The issue is that i can't fetch the data from this endpoint, but when i put a test API instead of my localhost, the code works. How to fetch data from that endpoint using my implementation? What is the probem of my code?</p>
  
  <p>Here are my errors in console.
  <a href="https://i.stack.imgur.com/b8T0e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b8T0e.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/0Iz5W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Iz5W.png" alt="enter image description here"></a></p>