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

274
Vistas
Is it nessesary to use getStaticProps with json import in Next.js?

I want to render static data that is coming from a JSON or typescript file and display it to the user. Do I have to use getStaticProps or can I simply import the data without getStaticProps? It's not clear to me after reading the next documentation.

projects.tsx

const projects: [
  {
    id: "6853939";
    name: "Project 01";
    title: "Title 01 ";
    previewImg: "/images/projectThumbnails/image01.jpg";
  },
  {
    id: "6853939";
    name: "Project 02";
    title: "Title 02 ";
    previewImg: "/images/projectThumbnails/image02.jpg";
  }
];

export default projects;

names.json

{
  "names": [
    { "name": "Full Name 01", "age": 34 },
    { "name": "Full Name 02", "age": 22 },
  ],
}

index.tsx

import projects from "../data/projects.tsx";
import names from "../data/names.json";

const IndexPage = () => {
  return (
    <>
      <div>
        {projects.map((i) => (
          <div key={i.id}>{i.title}</div>
        ))}
      </div>
      <div>
        {names.names.map((i) => (
          <div key={i.name}>{i.name}</div>
        ))}
      </div>
    </>
  );
};
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

It's totally up to you which approach you are going to use .

With getStaticProps:

server uses JSON data to inject data and create cache

Without getStaticProps:

JSON file would be injected in client side , without being cached

I prsonally recommend using getStaticProps

about 4 years ago · Santiago Trujillo Denunciar

0

Importing JSON in getStaticProps:

import yourJson from ('./somefile.json')


export async function getStaticProps(context) {
  
  //use your json here 
  
  return {
    props: {}, // will be passed to the page component as props
  }
}

about 4 years ago · Santiago Trujillo 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