Search code examples
next.jsgetserversideprops

next js console about getServerSideProps props


Can I check the value in terminal if I take console of the value received through getServerSideProps in the page component?

ex)

export const getServerSideProps = async({ req, res }) => {
  const data = useHook();
   // data = 1;
  return {
    data
  }
}

const MainPage = ({ data }) => {
   console.log(data); // i expect value = 1
   return <div>test</div>
}

can i check in terminal console??


Solution

  • Props that are passed from getServerSideProps should be like this:

    export const getServerSideProps = async({ req, res }) => {
      const data = useHook();
      return {
        props: {
            data
        },
      };
    }