Next.JS SSR in component

I want to integrate a module that only support server side rendering. This is project structure.

  • index.js
    • view.js
      • part.js (Class component)

I can use the module in getServerSideProps method in index.js. But I want to use it in part.js since there are some content I need to pass to the module that are available in part.js.

I’ve tried to pass a function in getServerSideProps as a prop to the component but it doesn’t allowed.

Can I run server side rendering code in react class component?


server side rendering just working on pages/ directory , you cant use it in component or ….

if you want to use It on pages/ files and its not working check 2 thing

  1. if you have _app.jsx in your project or not
  2. if you have __app.jsx you should define it right like this
import App from 'next/app';

const MyApp = ({ Component, pageProps }) => {

    return (
        <Component {...pageProps} />

MyApp.getInitialProps = async (appContext) => {
    const { pageProps } = await App.getInitialProps(appContext);
    const { ctx } = appContext;
    return { pageProps};

export default MyApp;