Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda