인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

오일중's profile image
오일중

asked

Learn React A-Z by following along [Reflecting version 19]

Retrieve post data and display it (remark)

[id].tsx 에서 params 빨간줄 부분 괜찮나요?

Written on

·

415

0

 

 

여기서 41번째줄 params 빨간줄 지나가도 괜찮나요 실행은 잘되는데 이유가 궁금합니다 undefine이라고 하는데... 잘모르겠네요

Next.jstddreactreduxtypescript

Answer 1

0

johnahn님의 프로필 이미지
johnahn
Instructor

안녕하세요!!! 

export const getStaticProps: GetStaticProps = async ({ params }) => {
const postData = await getPostData(params?.id as string)
return {
props: {
postData
}
}
}

이런 식으로 소스코드 바꿔주시면 됩니다. 

params가 무조건 있을 때만 postData를 가져오게 해 줍니다. 

감사합니다.

오일중님의 프로필 이미지
오일중
Questioner

감사합니다

오일중's profile image
오일중

asked

Ask a question