nextjs

nextjs SSR(server-side-rendering) 하는 법

직장인코딩 2022. 10. 12. 23:20
반응형

 

export async function getServerSideProps() {
  const { results } = await (
    await fetch("http://localhost:3000/api/movies")
  ).json();
  return {
    props: {
      results,
    },
  };
}
 
 

 

저기 getServerSideProps는 절대로 이름이 바뀌면 안된다

객체를 return 해주고 그 안에는 꼭 props가 있어야 되고 props 안에 객체가 있는데 그 안에

무엇을 return할지 정하면 되는 것이다.

저 results를 받아 올려면 그냥

 

저기 매개 변수 부분에 비구조화 할당으로 받아오면 된다.

 

반응형