Development/React.js
Next - getStaticProps
moretz0921
2022. 4. 7. 23:28
getStaticProps : 언제 접속해도 데이터가 바뀔 일이 없을 때 사용
- 데이터가 유동적으로 패칭될 필요없이 고정된 값을 불러올때 사용 ex) 블로그 게시글 등
- 수정 불가
- getStaticProps는 쓰기 까다로우니까 getServerSideProps를 주로 쓸 것!
문법
export const getStaticProps = async () => {
const res = await fetch(`url`);
const abc = await res.json();
return {
props: {
abc,
},
};
};
출처
https://yohanpro.com/posts/nextjs/data-fetching
Next.js에서 data-fetching하기 - Yohan's Developer Diary
Next.js팀 (Vercel)팀은 2020년 3월 10일에 9.3버전의 Next.js를 공개했다. 달라진 것 중에서 가장 눈에 띄는 것은 단연 data-fetcing 하는 메소드가 두 개가 추가된 것이다. 즉 pages 폴더 아래에 있는 엔드포인
yohanpro.com
Next.js - getStaticProps vs. getServerSideProps, 차이와 활용
Next.js 9.3 버전부터는 pre-rendering을 위한 data fetching을 위한 기존 기능인 getInitialProps가 getStaticProps, getServerSideProps, getStaticPaths로 분리되었습니다. 모두 pre-render가 필요한 경우에만..
beside-lab.tistory.com