I’m trying to use fetch to get data from Nest.js from localhost. I get no response. Am I doing something wrong?
const Container = styled.div`
flex: 1;
margin: 15px;
min-width: 300px;
height: 400px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
border: 1px solid black;
max-width: 300px;
`
const Name = styled.h1`
width: 100%;
height: 135%;
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
font-size: 20px;
`;
const Member = ({ item }) => {
return (
<Container>
<Name> {item.name}</Name>
<Birthday> {item.birth_date}</Birthday>
<Joindate> {item.created_at}</Joindate>
</Container>
)
}
export default Member
const Container = styled.div`
display: flex;
flex-wrap: wrap;
`
const Members = () => {
const [data, setData] = useState(null);
useEffect(() => {
const getData = async () => {
try {
const response = await fetch(
"http://localhost:3000/api/members"
);
let members = await response.json();
setData(members);
} catch(err) {
setData(null);
}
}
getData()
}, [])
return (
<Container>
{data && data.map((item) => (
<Member key={item.id} item={item} />
))}
</Container>
)
}
export default Members
What is the issue here?
I’m not getting any response.
these are the data that i want:
id
name
gender
birth_date
created_at
updated_at
What is the issue here?
I’m not getting any response.
these are the data that i want:
id
name
gender
birth_date
created_at
updated_at
2
Answers
This form was causing the issue. Not really sure why but it is fixed now.
Main
Stat
DEP
DBHELP
HelloContr
OneToMany