FRAMEWORK » NEXTJS

Server-side rendering

Shared getServerSideProps

Create a lib with the common getServerSideProps:

js
// lib/serverProps.js
export default async function getServerSideProps(ctx) {
  mydata = await axios.get('...');
  return {
    props: { data: mydata },
  };
}

Import it in all pages:

js
export { default as getServerSideProps } from '../lib/serverProps';