Review the code below to help me troubleshoot an issue I am encountering. I am utilizing Id to identify single content and titles for links.
When I console log params.title:
console: android-paging-advanced-codelab
However,
when I attempt to console log params.id:
console: undefined
I require access to both params within getStaticProps in order to retrieve the necessary data.
I tried using context by passing context and utilizing context.params.id, but encountered the same outcome.
Please take a look at the code provided below and offer your assistance!
Here is the code snippet for my getStaticPaths :
export async function getStaticPaths(){
const { data } = await client.query({
query: gql`
query {
postContents{
data{
attributes{
post_card{
data{
id
attributes{
TitleForLink
}
}
}
}
}
}
}
`
})
const paths = data.postContents.data.map((item)=> {
return {
params: {
id: item.attributes.post_card.data.id.toString(),
title: item.attributes.post_card.data.attributes.TitleForLink.toString(),
}
}
})
return {
paths,
fallback: false,
}
}
And here is the code for my getStaticProps:
export async function getStaticProps({params}){
const { data } = await client.query({
query: gql`
query {
postCards{
data{
id
attributes{
post_content{
data{
id
attributes{
Title
Description
}
}
}
}
}
}
}
`
})
console.log(params.id)
return {
props: {
content: data.postCards.data,
}
}
}