I am using react js and express js program. I have created express server, however my react js app is not working with my express js. I am showing you codes of react js below
import React, { useEffect, useState } from 'react';
const Get = () => {
const [users, setUsers] = useState([])
useEffect(() => {
fetch("http://localhost:3000/posts")
.then((response) => response.json())
.then((users) => {
setUsers(users);
})
}, []);
return (
<>
{users.map((post) => {
return (
<div>
<p>{post.date}</p>
</div>
)
})}
</>
)
}
export default Get
It says
Unhandled Rejection (TypeError): Failed to fetch
and I think that it is connected with my fetch request.
This is the information in my server:
[
{"_id":"617fa514d55c0cced18b1f6b","title":"New Title","description":"Hello World","date":"2021-11-01T08:26:52.000Z","__v":0},
{"_id":"617fa52bd55c0cced18b1f6d","title":"New Title","description":"Hello World","date":"2021-11-01T08:26:52.000Z","__v":0},
{"_id":"617fa52cd55c0cced18b1f6f","title":"New Title","description":"Hello World","date":"2021-11-01T08:26:52.000Z","__v":0}
]