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

229
Vistas
Struggling to convert "getStaticProps" .jsx to tsx on Nextjs application

It is an application consuming Printifull API that works well on .jsx with the following code:


import axios from "axios";

export default function ApiTest(props) {
  console.log(props);

  return(
    <></>
  (
}

export async function getStaticProps() {
  const headers = { Authorization: `Bearer ${process.env.PRINTIFUL_KEY}` };
  const res = await axios.get("https://api.printful.com/store/products", {
    headers,
  });
  const data = res.data;
  return {
    props: data,
  };
}

It is how the console looks with this script:

enter image description here

When I try to convert to .tsx doesn’t work, the following code shows the way that I am trying to do that.


import { GetStaticProps } from "next";
import axios from "axios";

export default function ProductList(props: any) {
  console.log(props);
  return (
  <></>
)
}

interface Props {
  headers: any;
  res: any;
  data: any;
}

const token = process.env.PRINTIFUL_KEY as string;
const url = "https://api.printful.com/store/products";

export const getStaticProps: GetStaticProps<Props> = async () => {
  const headers = { Authorization: `Bearer ${token}` };
  const res = await axios.get(url, {
    headers,
  });
  const data = res.data;
  return {
    props: data,
  };
};

Now, look at my console. It does not work showing the API content. enter image description here

I hope to get close to the solution.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is the way that I found to make it work:

import { InferGetServerSidePropsType } from "next";

type Product = {
  list: object[];
  result: Array<{
    id: number;
    name: string;
    thumbnail_url: string;
  }>;
};

export const getStaticProps = async () => {
  const headers = { Authorization: `Bearer ${process.env.PRINTIFUL_KEY}` };
  const res = await fetch("https://api.printful.com/store/products", {
    headers,
  });
  const products: Product = await res.json();

  return {
    props: {
      products: products.result,
    },
  };
};

export default function TypeTest({
  products,
}: InferGetServerSidePropsType<typeof getStaticProps>) {
  console.log(products);
  return (
    <>
      
    </>
  );
}

enter image description here

I still looking to alternative solutions.

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