This question already has answers here:
JavaScript: Difference between .forEach() and .map() (15 answers)
Closed 5 days ago.
Hi I´m trying to fetch data and display it in a list but somehow it isn´t working. Can someone tell me whats wrong with the following function? It isn´t displaying anything or it is telling me that the data isn´t valid as child props. thanks for answers.
export async function getServerSideProps(context) {
const res = await fetch('
https://jsonplaceholder.typicode.com/posts')
const data = await res.json()
return {
props: { data }, // will be passed to the page component as props
}
}
export default function Home({data}) {
return (
Hello World
{
data.forEach(item => {
return {item.title}
})
}
)
}
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)