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

271
Visualizações
import a single getServerSideProps method to multiple pages in Nextjs

I'm trying to import the getServerSideProps method from this page to another and use it throughout multiple pages. How can I do that?

Heres my code:

import DashboardLayout from "@app/layout/DashboardLayout";
import Overview from "@containers/dashboard/Overview";
import { parsedCookie } from "@infrastructure/utils/functions";

const OverviewPage = () => {
  return (
    <DashboardLayout>
      <Overview />
    </DashboardLayout>
  );
};

export default OverviewPage;

export const getServerSideProps = async (context) => {
  const token = parsedCookie(context.req);
  const { accessToken, refreshToken } = token;
  if (!accessToken || !refreshToken) {
    return {
      redirect: {
        destination: "/",
        permanent: false,
      },
    };
  }

  return {
    props: {},
  };
};
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I found the answer . heres how you can use a pages datafetching method on a another page

import DashboardLayout from "@app/layout/DashboardLayout";
import MyCourses from "@containers/dashboard/MyCourses";
import { getServerSideProps } from "../index";

const MyCoursesPage = () => {
  return (
    <DashboardLayout>
      <MyCourses />
    </DashboardLayout>
  );
};

export default MyCoursesPage;

export { getServerSideProps };
about 4 years ago · Juan Pablo Isaza Relatório

0

You can not import getServerSideProps they are unique for each page but if all pages in first load should get same data you can add getIntialProps in your _app.js file. for more info you can read customizing _app.js files

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