enter image description hereI want to fetch data using this way:
import React, { useState, useEffect } from 'react';
const Home = () => {
useEffect (async () =>{
const response = await fetch('http://localhost:4000/user')
const myJson = await response.json();
console.log(JSON.stringify(myJson));
})
return(
<div>
<h1>Home Page</h1>
</div>
)
}
export default Home;
The result of localhost:4000 (generated with node js) is: { _id: 5da4a2066f90a24d4f82787a, name: 'Gregor', email: 'test@eee.com', age: 3, hasCar: false, favColors: [ 'green', 'red' ] }
. 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?