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

144
Vistas
Returning data from getStaticProps

I'm trying to create a function that fetches data from The Guardian API but seem to be getting an error. The response returns this information: enter image description here

And here is the code for the asynchronous function:

export async function getStaticProps() {
  try {
    const res = await fetch(
      "https://content.guardianapis.com/search?api-key=xxxxxxxx&show-fields=thumbnail"
    );
    const { results } = await res.json();
    const newsList = results.map((news) => {
      return { ...news };
    });
    return {
      props: { newsList },
    };
  } catch (err) {
    console.error(err);
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You almost got it. Only 1 thing you are missing is to return props even in the catch block

export async function getStaticProps() {
  try {
    const res = await fetch(
      "https://content.guardianapis.com/search?api-key=xxxxxxxx&show-fields=thumbnail"
    );
    const { results } = await res.json();
    const newsList = results.map((news) => {
      return { ...news };
    });
    return {
      props: { newsList },
    };
  } catch (err) {
    console.error(err);
    return {
      notFound: true /// for rendering 404 page
    };
  }
}
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