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

103
Views
Server side prop value undefined only in the component section

I have the following where I am able to print the data coming from getServerSideProps. But when I pass it on to the component section, the prop value posts is undefined. Why?

The following is under /pages and is inside the base index.tsx file.

import type { NextPage } from 'next'
import Post from '../components/Post'

const Home: NextPage = ({ posts }) => {

  // This prints undefined. This is the issue.  
  console.log(posts)

  return (
    <div>
        <Post posts={posts}/>
    </div>
  )
}

export default Home

export const getServerSideProps = async () => {
  const response = await fetch('http://localhost:8080/posts/all')
  const data = await response.json()

  // this prints correctly
  console.log(data)

  return {
    props: {
      posts: data
    }
  }
};

Updates to show _app.tsx file

import Home from '../pages';

const TestApp = () => {
  return <>
      <Home />
  </>
}

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

0

Remove the custom _app.tsx file or update it to accept a Component prop and render it as shown in the Nextjs documentation for a Custom App.

The problem is this custom App is always rendering the Home component (with no props) so it's printing undefined. Then, try navigating to / on localhost. It should render the index.tsx file and properly invoke getServerSideProps and pass the result to the component as you expect.

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!