Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
why getInitialProps return undefined

In my index page like this:

function Index({posts}) {
    console.log(posts);
    return (
        <div>
            Homepage
            {/* {posts && posts.length > 0 && posts.map(post => <h1 key={post._id}>{ post.title}</h1>)} */}
        </div>

    )
}

Index.getInitialProps = async ctx => {
  try {
        const res = await axios({
            method: "GET",
            url: 'https://jsonplaceholder.typicode.com/posts'
        })
      return {posts: res.data}
      
    } catch (error) {
      return  {errorLoading: true}
    }
}

export default Index;

console.log(res.data) work successfully. But I only get console.log(posts) undefined. why?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I use custom app. I forgot add pageProps in _app.js. After see https://nextjs.org/docs/advanced-features/custom-app I fix these. Thanks for everyone to help me

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!