Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda